PySpark Error in Saving DataFrame to CSV

pyspark

#1

Hi Friends,

I am trying to save a Dataframe to CSV in PySpark but getting an error.

I started my pySpark with :

pyspark --packages com.databricks:spark-csv_2.11:1.5.0 --master yarn --conf spark.io.port=54322

Below is my code and the error I am getting:

orders_DF = sqlContext.read.load("/user/macksv17/practice4/question3/orders")
orders_DF.write.format(‘com.databricks.spark.csv’).save("/user/macksv17/practice4/question3/results_output")
Traceback (most recent call last):
File “”, line 1, in
File “/usr/hdp/current/spark-client/python/pyspark/sql/readwriter.py”, line 397, in save
self._jwrite.save(path)
File “/usr/hdp/current/spark-client/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py”, line 813, in call
File “/usr/hdp/current/spark-client/python/pyspark/sql/utils.py”, line 45, in deco
return f(*a, **kw)
File “/usr/hdp/current/spark-client/python/lib/py4j-0.9-src.zip/py4j/protocol.py”, line 308, in get_return_value
py4j.protocol.Py4JJavaError: An error occurred while calling o51.save.
: java.lang.NoSuchMethodError: scala.Predef$.$conforms()Lscala/Predef$$less$colon$less;
at com.databricks.spark.csv.util.CompressionCodecs$.(CompressionCodecs.scala:29)
at com.databricks.spark.csv.util.CompressionCodecs$.(CompressionCodecs.scala)
at com.databricks.spark.csv.DefaultSource.createRelation(DefaultSource.scala:198)
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: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: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)

Thanks.


Learn Spark 1.6.x or Spark 2.x on our state of the art big data labs

  • Click here for access to state of the art 13 node Hadoop and Spark Cluster


#2

Launch pyspark with below package and try

pyspark --packages com.databricks:spark-csv_2.10:1.5.0


#3

Thank you very much Sunil. It’s working now !


#4