File format conversation - class not found error


#1

Hi ,

I am trying to convert/save the avro data file to text file with gzip compression with below code

import avro.schema
ordersAvro=sqlContext.read.load("/user/krishnatejathatavarthi/teja_arun/problemFour/orders_avro",“com.databricks.spark.avro”)
ordersAvro.map(lambda rec: str(rec[0])+"\t"+str(rec[1])+"\t"+str(rec[2])+"\t"+str(rec[3])).saveAsTextFile("/user/krishnatejathatavarthi/teja_arun/problemFour/text-gzip-compress",“classOf[org.apache.hadoop.io.compress.GzipCodec]”)

Here, i am facing an error with class not found

Traceback (most recent call last):
File “”, line 1, in
File “/usr/hdp/2.5.0.0-1245/spark/python/pyspark/rdd.py”, line 1503, in saveAsTextFile
compressionCodec = self.ctx._jvm.java.lang.Class.forName(compressionCodecClass)
File “/usr/hdp/2.5.0.0-1245/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py”, line 813, in call
File “/usr/hdp/2.5.0.0-1245/spark/python/pyspark/sql/utils.py”, line 45, in deco
return f(*a, **kw)
File “/usr/hdp/2.5.0.0-1245/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 z:java.lang.Class.forName.
: java.lang.ClassNotFoundException: classOf[org/apache/hadoop/io/compress/GzipCodec]
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
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)

Please help me with the issue to solve the problem.

Thanks