Spark 2.4.1无法从HDFS读取Avro文件

时间:2019-06-10 19:00:10

标签: apache-spark hdfs bigdata avro avro-tools

我有一个简单的代码块来编写,然后以Avro格式读取数据帧。由于Spark 2.4.x中已经内置了Avro库,因此

Avro文件写入成功,并且在HDFS中生成了文件。但是,当我读取文件时会引发AbstractMethodError异常。谁能分享我的光芒?

我通过在Zeppelin节点手册Spark解释器中添加软件包org.apache.spark:spark-avro_2.11:2.4.1来使用Spark内部库。

我的简单代码块:

%pyspark

test_rows = [ Row(file_name = "test-guangzhou1", topic='camera1', timestamp=1, msg="Test1"),  Row(file_name = "test-guangzhou1", topic='camera1', timestamp=2, msg="Test2"), Row(file_name = "test-guangzhou3", topic='camera3', timestamp=3, msg="Test3"), Row(file_name = "test-guangzhou1", topic='camera1', timestamp=4, msg="Test4") ]

test_df = spark.createDataFrame(test_rows)

test_df.write.format("avro")
    .mode('overwrite').save("hdfs:///tmp/bag_parser279181359_3")

loaded_df =  spark.read.format("avro").load('hdfs:///tmp/bag_parser279181359_3')

loaded_df.show()

我看到的错误消息:

Py4JJavaError: An error occurred while calling o701.collectToPython.
: java.lang.AbstractMethodError
    at org.apache.spark.sql.execution.FileSourceScanExec.inputRDD$lzycompute(DataSourceScanExec.scala:337)
    at org.apache.spark.sql.execution.FileSourceScanExec.inputRDD(DataSourceScanExec.scala:331)
    at org.apache.spark.sql.execution.FileSourceScanExec.inputRDDs(DataSourceScanExec.scala:357)
    at org.apache.spark.sql.execution.WholeStageCodegenExec.doExecute(WholeStageCodegenExec.scala:627)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:137)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$execute$1.apply(SparkPlan.scala:133)
    at org.apache.spark.sql.execution.SparkPlan$$anonfun$executeQuery$1.apply(SparkPlan.scala:161)
    at org.apache.spark.rdd.RDDOperationScope$.withScope(RDDOperationScope.scala:151)
    at org.apache.spark.sql.execution.SparkPlan.executeQuery(SparkPlan.scala:158)
    at org.apache.spark.sql.execution.SparkPlan.execute(SparkPlan.scala:133)
    at org.apache.spark.sql.execution.SparkPlan.getByteArrayRdd(SparkPlan.scala:289)
    at org.apache.spark.sql.execution.SparkPlan.executeTake(SparkPlan.scala:381)
    at org.apache.spark.sql.execution.CollectLimitExec.executeCollect(limit.scala:38)
    at org.apache.spark.sql.Dataset$$anonfun$collectToPython$1.apply(Dataset.scala:3259)
    at org.apache.spark.sql.Dataset$$anonfun$collectToPython$1.apply(Dataset.scala:3256)
    at org.apache.spark.sql.Dataset$$anonfun$53.apply(Dataset.scala:3373)
    at org.apache.spark.sql.execution.SQLExecution$$anonfun$withNewExecutionId$1.apply(SQLExecution.scala:79)
    at org.apache.spark.sql.execution.SQLExecution$.withSQLConfPropagated(SQLExecution.scala:144)
    at org.apache.spark.sql.execution.SQLExecution$.withNewExecutionId(SQLExecution.scala:74)
    at org.apache.spark.sql.Dataset.withAction(Dataset.scala:3367)
    at org.apache.spark.sql.Dataset.collectToPython(Dataset.scala:3256)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.lang.Thread.run(Thread.java:748)

(<class 'py4j.protocol.Py4JJavaError'>, Py4JJavaError(u'An error occurred while calling o701.collectToPython.\n', JavaObject id=o702), <traceback object at 0x7fc031b5c878>)

2 个答案:

答案 0 :(得分:2)

AbstractMethodError

当应用程序尝试调用抽象方法时抛出。通常, compiler 会捕获此错误;如果自从上次编译当前执行的方法以来某个类的定义发生了不兼容的更改,则只有在运行时才会发生此错误。

AFAIK,您必须调查用于编译和运行的版本。

答案 1 :(得分:0)

here有一个类似但不同的问题,涉及在emr-5.28.0上使用spark-avro。这与此问题中讨论的原因不同(因为早在emr-5.28.0可用之前就曾问过这个问题),但它非常相似,以至于我认为我会链接到my answer万一有人因相似的堆栈跟踪和相似的问题而偶然发现了这个问题。