我移植了一些代码从星火1.6至2.1星火与下面的问题搏斗行数据帧:问题,以创建包含Option [T]
这星火1.6
import org.apache.spark.sql.types.{LongType, StructField, StructType}
val schema = StructType(Seq(StructField("i", LongType,nullable=true)))
val rows = sparkContext.parallelize(Seq(Row(Some(1L))))
sqlContext.createDataFrame(rows,schema).show
完美地工作在星火2.1.1相同的代码:
import org.apache.spark.sql.types.{FloatType, LongType, StructField, StructType}
val schema = StructType(Seq(StructField("i", LongType,nullable=true)))
val rows = ss.sparkContext.parallelize(Seq(Row(Some(1L))))
ss.createDataFrame(rows,schema).show
提供了以下运行时异常:
org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 8.0 failed 4 times, most recent failure: Lost task 0.3 in stage 8.0 (TID 72, i89203.sbb.ch, executor 9): java.lang.RuntimeException: Error while encoding: java.lang.RuntimeException: scala.Some is not a valid external type for schema of bigint
那么,如果我想要可空Long
而不是使用Option[Long]
,我应该如何将这些代码转换为Spark 2.x?
感谢这个信息。我知道打算输入数据集它是最干净的解决方案,但也需要一些时间来重构代码 –
@RaphaelRoth唯一的问题是,周围没有任何词汇。这是标准。 – eliasah
我不太确定强类型数据集是否真的会成为新标准......我有些怀疑 –