Big Data spark mushroom cloud prequel 16th: Scala implicits programming thorough combat and spark source appreciation (study notes)

Source: Internet
Author: User

This lesson:
    1. The use of Scala's implicit in the Spark source code
    2. Scala's implicit programming operation combat
    3. Scala's implicit enterprise-class best practices
The use of Scala's implicit in the Spark source codeThe meaning of this thing is very significant, the RDD itself does not have a key, value, but it is the time of its own interpretation into a key Value of the method to read, the RDD itself is a Record. The RDD itself does not have a reducebykey, it is the use of implicit conversion, the transformation of the Reducebykey method in the Pairrddpartition category it only look at the type, see what they need is the RDD, and then return is the code needed pairrddfunction, This method of implicit conversion is used. If this implicit conversion is not found for the source, target, associated, and associated images, it is necessary to move it into the code, which is also important for the structure of the codes. Scala's implicit programming operation CombatImplicit conversions have many different parts, including implicit parameters, implicit conversions, implicit and implicit images, and implicit conversions are features of Scala. Scala language because there is an implicit conversion so there is a mistake before you will be able to judge the implicit in the same meaning can be out of the function of the Imperial Army, if any, it will adjust the implicit conversion method to complete this conversion. The Scala implicit conversion has the following methods
    1. The method of creating an implicit conversion in the associated image:
      The class man itself has no makemiracles method, and it is impossible to adjust it.
      Create a man's Object, and if you add the implicit function to the guy's own companion image, it will find its own function in the last moment of the bug! See if there is a way to convert it, and discover it! will be self-makemiracles method. The success of an implicit conversion! Here is the ability to add implicit conversions, meaning that the function of class man is expanded

    2. Directly into the implicit method, in this sparksql example implicit is an object,

      In the following example, it is also the first to create a implicit object, then import the function of this type, and then the man can also be used under the function of implicit object in the implicit conversion.
    3. Implicit parameters, which can be used to transmit the parameters for an implied number of variables.
      First write a function:def talk (name:string) (implicit content:string) = println (name + ":" + content), the 2nd is an implicit reference, and then the talk-side If there are no implicit parameters, the editor will report it! At this point, you can define an implicit reference, and the implicit conversion succeeds!

Big Data spark mushroom cloud prequel 16th: Scala implicits programming thorough combat and spark source appreciation (study notes)

Related Article

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.