object Spark01_RDD_Part {
def main(args: Array[String]): Unit = {
val sparkConf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("r1")
val sc: SparkContext = new SparkContext(sparkConf)
val rdd: RDD[(String, String)] = sc.makeRDD(List(
("nba","......."),
("cuba","......."),
("cba","......."),
("nba","......."),
),3)
val partRDD: RDD[(String, String)] = rdd.partitionBy(new myPartitioner)
partRDD.saveAsTextFile("output")
sc.stop()
}
}
class myPartitioner extends Partitioner{
override def numPartitions: Int = 3
override def getPartition(key: Any): Int = {
key match {
case "nba" => 0
case "cba" => 1
case _ => 2
}
}
}