火花保存df作为csv抛出错误

时间:2016-05-16 17:37:07

标签: apache-spark spark-csv

我正在使用pyspark并加载了数据框。当我尝试将其保存为CSV文件时,我收到以下错误。我像这样初始化火花:

./pyspark --master local[4] --executor-memory 14g --driver-memory 14g --conf spark.local.dir=/mnt/bigdisk/spark_tmp --packages com.databricks:spark-csv_2.11:1.4.0

错误:

df.write.save("/mnt/disk/df.csv", 'com.databricks.spark.csv', header = 'true', codec = None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/spark/python/pyspark/sql/readwriter.py", line 397, in save
    self._jwrite.save(path)
  File "/home/ubuntu/spark/python/lib/py4j-0.9-    src.zip/py4j/java_gateway.py", line 813, in __call__
  File "/home/ubuntu/spark/python/pyspark/sql/utils.py", line 45, in deco
return f(*a, **kw)
  File "/home/ubuntu/spark/python/lib/py4j-0.9-src.zip/py4j/protocol.py", line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o232.save.
: java.lang.NoClassDefFoundError: Could not initialize class com.databricks.spark.csv.util.CompressionCodecs$
    at com.databricks.spark.csv.DefaultSource.createRelation(DefaultSource.scala:189)
    at org.apache.spark.sql.execution.datasources.ResolvedDataSource$.apply(ResolvedDataSource.scala:222)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:148)
    at org.apache.spark.sql.DataFrameWriter.save(DataFrameWriter.scala:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:381)
    at py4j.Gateway.invoke(Gateway.java:259)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:209)
    at java.lang.Thread.run(Thread.java:745)

1 个答案:

答案 0 :(得分:3)

当我使用Spark的预编译版本1.6.1时,解决方法是更改​​为2.10版本的Scala库,如下所示:

./pyspark --packages com.databricks:spark-csv_2.10:1.4.0