【发布时间】:2018-10-30 19:55:22
【问题描述】:
如果我理解正确,可以将 ArrayType 添加为 Spark DataFrame 列。我正在尝试使用 withColumn 方法将多维数组添加到现有的 Spark DataFrame 中。我的想法是让这个数组可用于每个 DataFrame 行,以便使用它从 map 函数发回信息。
我得到的错误是 withColumn 函数正在寻找 Column 类型,但它正在获取一个数组。是否有任何其他功能可以添加ArrayType?
object TestDataFrameWithMultiDimArray {
val nrRows = 1400
val nrCols = 500
/** Our main function where the action happens */
def main(args: Array[String]) {
// Create a SparkContext using every core of the local machine, named RatingsCounter
val sc = new SparkContext("local[*]", "TestDataFrameWithMultiDimArray")
val sqlContext = new SQLContext(sc)
val PropertiesDF = sqlContext.read
.format("com.crealytics.spark.excel")
.option("location", "C:/Users/tjoha/Desktop/Properties.xlsx")
.option("useHeader", "true")
.option("treatEmptyValuesAsNulls", "true")
.option("inferSchema", "true")
.option("addColorColumns", "False")
.option("sheetName", "Sheet1")
.load()
PropertiesDF.show()
PropertiesDF.printSchema()
val PropertiesDFPlusMultiDimArray = PropertiesDF.withColumn("ArrayCol", Array.ofDim[Any](nrRows,nrCols))
}
感谢您的帮助。
亲切的问候,
约翰
【问题讨论】:
标签: apache-spark apache-spark-sql apache-spark-dataset