我正在尝试将以下代码转换为在 spark 1.6 上运行,但是我遇到了某些问题。同时将 sparksession 转换为上下文
object TestData {
def makeIntegerDf(spark: SparkSession, numbers: Seq[Int]): DataFrame =
spark.createDataFrame(
spark.sparkContext.makeRDD(numbers.map(Row(_))),
StructType(List(StructField("column", IntegerType, nullable = false)))
)
}
我如何转换它以使其在 spark 1.6 上运行
SparkSession
仅从spark 2.0开始支持。所以,如果你想使用火花1.6,那么你需要创建SparkContext
并sqlContext
在驱动程序类,并将其传递给函数。
所以你可以创建
val conf = new SparkConf().setAppName("simple")
val sparkContext = new SparkContext(conf)
val sqlContext = new SQLContext(sparkContext)
然后将该函数调用为
val callFunction = makeIntegerDf(sparkContext, sqlContext, numbers)
你的功能应该是
def makeIntegerDf(sparkContext: SparkContext, sqlContext: SQLContext, numbers: Seq[Int]): DataFrame =
sqlContext.createDataFrame(
sparkContext.makeRDD(numbers.map(Row(_))),
StructType(List(StructField("column", IntegerType, nullable = false)))
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句