我正在使用 spark-shell 来试验 Spark 的 HashPartitioner。错误显示如下:
scala> val data = sc.parallelize(List((1, 3), (2, 4), (3, 6), (3, 7)))
data: org.apache.spark.rdd.RDD[(Int, Int)] = ParallelCollectionRDD[0] at parallelize at <console>:24
scala> val partitionedData = data.partitionBy(new spark.HashPartitioner(2))
<console>:26: error: type HashPartitioner is not a member of org.apache.spark.sql.SparkSession
val partitionedData = data.partitionBy(new spark.HashPartitioner(2))
^
scala> val partitionedData = data.partitionBy(new org.apache.spark.HashPartitioner(2))
partitionedData: org.apache.spark.rdd.RDD[(Int, Int)] = ShuffledRDD[1] at partitionBy at <console>:26
第二次操作失败,而第三次操作成功。为什么 spark-shell 会在 org.apache.spark.sql.SparkSession 的包中查找 spark.HashPartitioner 而不是 org.apache.spark?