RDD基础学习-[5]PairRDD关联函数基础
2016-12-07 00:28
190 查看
简介
PairRDD间关联API,注意返回值类型 def join[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, W]] def join[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, W]]] = { /* compiled code */ } def leftOuterJoin[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, Option[W]] def leftOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, scala.Option[W]]]] = { /* compiled code */ } def rightOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, Tuple2[Option[V], W]] def rightOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], W]]] = { /* compiled code */ } def fullOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, scala.Tuple2[Option[V], Option[W]] def fullOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], scala.Option[W]]]] = { /* compiled code */ }
package com.dt.spark.main.RDDLearn.PairRDDJoinFunAPI
import org.apache.spark.{SparkConf, SparkContext}
/**
* Created by on 16/12/06.
*/
//==========================================
/*
PairRDD间关联API,注意返回值类型 def join[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, W]] def join[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, W]]] = { /* compiled code */ } def leftOuterJoin[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, Option[W]] def leftOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, scala.Option[W]]]] = { /* compiled code */ } def rightOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, Tuple2[Option[V], W]] def rightOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], W]]] = { /* compiled code */ } def fullOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, scala.Tuple2[Option[V], Option[W]] def fullOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], scala.Option[W]]]] = { /* compiled code */ }
*/
object PairRDDJoinFunAPI {
def main(args: Array[String]) {
val conf = new SparkConf()
conf.setAppName("test")
conf.setMaster("local")
val sc = new SparkContext(conf)
//==========================================
/*
def join[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, W]]
def join[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, W]]] = { /* compiled code */ }
def leftOuterJoin[W](other :Tuple2[K, W]) : Tuple2[K, Tuple2[V, Option[W]]
def leftOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[V, scala.Option[W]]]] = { /* compiled code */ }
def rightOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, Tuple2[Option[V], W]]
def rightOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], W]]] = { /* compiled code */ }
def fullOuterJoin[W](other : Tuple2[K, W]) : Tuple2[K, scala.Tuple2[Option[V], Option[W]]
def fullOuterJoin[W](other : org.apache.spark.rdd.RDD[scala.Tuple2[K, W]], numPartitions : scala.Int) : org.apache.spark.rdd.RDD[scala.Tuple2[K, scala.Tuple2[scala.Option[V], scala.Option[W]]]] = { /* compiled code */ }
*/
val KVPairRDD1 = sc.parallelize(List(("beijing", "京"), ("shaanxi", "陕"),("jiangsu", "苏"),("shandong", "鲁"),("guangxi","桂")))
val KVPairRDD2 = sc.parallelize(List( ("beijing", "北京"), ("shaanxi", "西安"),("jiangsu", "南京"),("shandong", "济南")))
def getVauleOfOption(in:Option[String]):String = in match {
case Some(x) => x
case None => "NULL"
}
val res = KVPairRDD1.fullOuterJoin(KVPairRDD2).map(a=>(a._1,getVauleOfOption(a._2._1),getVauleOfOption(a._2._2)))
res.foreach(println(_))
// (guangxi,桂,NULL)
// (shaanxi,陕,西安)
// (shandong,鲁,济南)
// (beijing,京,北京)
// (jiangsu,苏,南京)
sc.stop()
}
}
相关文章推荐
- RDD基础学习-[1]RDD建立与WordCount
- RDD基础学习-[3]RDD聚合函数基础
- Spark学习之键值对(pair RDD)操作(3)
- RDD基础学习-[4]PairRDD聚合函数基础
- Spark MLlib 入门学习笔记 - RDD基础
- 有关RDD的基础学习1
- spark学习-SparkSQL--13-java版JavaRDD与JavaPairRDD的互相转换
- RDD基础学习-[2]RDD分区
- 【spark 深入学习 06】RDD编程之旅基础篇02-Spaek shell
- Spark基础脚本入门实践3:Pair RDD开发
- Spark2.x基础学习之RDD理解
- Spark 基础学习第一讲:弹性分布式数据集RDD
- Spark学习之键值对(pair RDD)操作
- Spark学习之键值对(pair RDD)操作(3)
- Spark学习-RDD编程基础
- Spark MLlib 学习入门笔记 - RDD基础
- spark内核源码学习-RDD基础篇
- J2ME学习(四)——将MIDlet和界面分离(比较基础)
- java线程学习基础
- SQL的详细语法介绍——对于学习数据库最基础知识[转]