gpt4 book ai didi

scala - org.apache.avro.UnresolvedUnionException : Not in union ["long" ,"null"]

转载 作者:行者123 更新时间:2023-12-03 23:23:14 27 4
gpt4 key购买 nike

我编写了这段代码,使用 Spark (1.3.0)、Scala (2.10.4) 和 Spark Avro (1.0.0) 将 Spark 数据帧保存到 avro 文件中

  def getMatchingLine(line: String) : Option[Row] = {
val regex = "^.*&50=(\\w+)&.*&62-\\d=8&63-\\d=(\\w+)&.*timestamp=(\\d+).*$".r
line match {
case regex(a, b, c) => Some(Row(a, b, c))
case _ => None
}
}

val schema = StructType(List(StructField("a", StringType, true), StructField("b", StringType, true), StructField("c", LongType, true)))
val rdd = sc.textFile(inputPath).cache()
val rdd = rdd.map(getMatchingLine).filter(_.isDefined).flatMap(x => x)
val df = sqlSc.createDataFrame(rdd, schema)
df.save("/user/foo/", "com.databricks.spark.avro")

错误消息的堆栈跟踪是
ion: org.apache.avro.UnresolvedUnionException: Not in union ["long","null"]: 1426647603695
at org.apache.avro.file.DataFileWriter.append(DataFileWriter.java:296)
at org.apache.avro.mapred.AvroOutputFormat$1.write(AvroOutputFormat.java:169)
at org.apache.avro.mapred.AvroOutputFormat$1.write(AvroOutputFormat.java:166)
at org.apache.spark.SparkHadoopWriter.write(SparkHadoopWriter.scala:96)
at org.apache.spark.rdd.PairRDDFunctions$$anonfun$13.apply(PairRDDFunctions.scala:1073)
at org.apache.spark.rdd.PairRDDFunctions$$anonfun$13.apply(PairRDDFunctions.scala:1059)
at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:61)
at org.apache.spark.scheduler.Task.run(Task.scala:64)
at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:203)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

最佳答案

尝试将元组中的 3'd 位置转换为 long。它可能是整数,不能转换为长整数。

一些(行(a,b,(长)c))

关于scala - org.apache.avro.UnresolvedUnionException : Not in union ["long" ,"null"],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35963285/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com