官术网_书友最值得收藏!

Passing functions to Spark (Java)

In Java, to create a function you will have to implement the interfaces available in the org.apache.spark.api.java function package. There are two popular ways to create such functions:

  • Implement the interface in your own class, and pass the instance to Spark.
  • Starting Java 8, you can use Lambda expressions to pass off the functions to the Spark framework.

Let's implement the preceding word count examples in Java:

Figure 2.13: Code example of Java implementation of word count (inline functions)

If you belong to a group of programmers who feel that writing inline functions makes the code complex and unreadable (a lot of people do agree to that assertion), you may want to create separate functions and call them as follows:

Figure 2.14: Code example of Java implementation of word count

主站蜘蛛池模板: 荔波县| 健康| 灵宝市| 仙游县| 宁海县| 上虞市| 丰镇市| 彩票| 德令哈市| 天峻县| 潍坊市| 五台县| 湘阴县| 响水县| 井陉县| 天柱县| 鹰潭市| 辽阳市| 轮台县| 双桥区| 顺平县| 古丈县| 镶黄旗| 横峰县| 大姚县| 峡江县| 阜康市| 聊城市| 油尖旺区| 灵川县| 比如县| 香格里拉县| 乌拉特前旗| 赣榆县| 商河县| 吴江市| 黑山县| 海淀区| 阿拉善盟| 漾濞| 收藏|