【发布时间】:2017-03-15 21:26:53
【问题描述】:
我已经使用以下代码创建了一个架构
val schema= new StructType().add("city", StringType, true).add("female", IntegerType, true).add("male", IntegerType, true)
从
创建了一个RDDval data = spark.sparkContext.textFile("cities.txt")
转换为 Row 的 RDD 以应用架构
val cities = data.map(line => line.split(";")).map(row => Row.fromSeq(row.zip(schema.toSeq)))
val citiesRDD = spark.sqlContext.createDataFrame(cities, schema)
这给了我一个错误
java.lang.RuntimeException: Error while encoding: java.lang.RuntimeException: scala.Tuple2 is not a valid external type for schema of string
【问题讨论】:
标签: scala apache-spark dataframe apache-spark-sql