74th: Thinking about pattern matching in Scala from the perspective of Spark source

Source: Internet
Author: User

Today, Mr. Wang studied the function of pattern matching in Scala from the source point of view. Let's look at this pattern match in the source code:

From the code we can see that case Registerworker (Id,workerhost,........) {} Here is a pattern match, and our pattern-matching class registerworker before it is defined, such as:

We can see that our pattern matching class is already defined, and when our master receives a message from the worker, it makes a pattern match:

There is also a knowledge point where we can find that when we do pattern matching, we do not use the new method to create a new instance, but instead use the Registerworker (ID,.....) directly. And here, we are using the associated application method of the class. When a pattern match is made, the Unapply method is used to parse the content that the instance passes over.

Share more of the Scala resources:

Baidu Cloud Disk: http://pan.baidu.com/s/1gd7133t

Micro Cloud Disk: http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416

360 Cloud Disk: Http://yunpan.cn/cQN9gvcKXe26M (extract code: 13CD)

Information from DT Big Data Dream Factory public account: Dt_spark

Follow the account for more information about Scala learning

74th: Thinking about pattern matching in Scala from the perspective of Spark source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.