2

我正在使用 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)
4

1 回答 1

4

由于我使用的是 Spark 的预编译版本 1.6.1,因此修复方法是更改​​为 Scala 库的 2.10 版本,如下所示:

./pyspark --packages com.databricks:spark-csv_2.10:1.4.0
于 2016-05-16T18:03:05.817 回答