2016-05-16 78 views
1

我正在使用pyspark並加載了一個數據框。當我嘗試將其保存爲CSV文件時,出現以下錯誤。我初始化火花像這樣:Spark save df as csv throws error

./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) 
+0

你用Scala 2.11編譯過Spark嗎? – zero323

+0

嘗試使用com.databricks:spark-csv_2.11:1.3.0 –

+0

您使用的是什麼版本的Spark? – RudyVerboven

回答

2

由於我用的是預編譯的版本星火1.6.1,修復被更改爲2.10版本的Scala庫的像這樣:

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