1
votes

Hey I have a table in a ASV(chr(1) separated hive datafile) format. And I want to extract certain columns, group by a combo of two columns and do something within each group.

col1    col2    col3     col4
1A      1B      20150101 100
1A      1C      20150101 90
1A      1B      20150102 40
...

I want the output to be like

key      value 
(1A, 1B) [(20150101, 100), (20150102, 40)...]
(1A, 1C) [(20150101,90)...]

What I have done in pyspark so far:

And the error looks like:

textfile = sc.textFile("hdfs://hostname:8020/user/hive/warehouse/myfolder")
textfile.count()
# 53 million
result = textfile.map(lambda line: line.split(chr(1)))
result = result.map( lambda l: ((l[20], l[4]), (l[2], l[13])) )
result.take(10)
# my result variable looks like this:
#[((u'A1', u'A2'), (u'2011-03-25', u'665.000000')),
# ((u'A1', u'B2'), (u'2013-01-07', u'1073.800000')),
#  ...
result_group = result.groupByKey()
result_group.take(10)

But it popped up error message like below, I don't know if that is my syntax error or it is the system set up error:

---------------------------------------------------------------------------
Py4JJavaError                             Traceback (most recent call last)
<ipython-input-22-dcef1140b3a8> in <module>()
----> 1 result_group.take(10)

/opt/cloudera/parcels/CDH-5.1.0-1.cdh5.1.0.p0.53/lib/spark/python/pyspark/rdd.py in take(self, num)
    866                 partitionsToTake = self.ctx._gateway.new_array(self.ctx._jvm.int, 1)
    867                 partitionsToTake[0] = partition
--> 868                 iterator = mapped._jrdd.collectPartitions(partitionsToTake)[0].iterator()
    869                 items.extend(mapped._collect_iterator_through_file(iterator))
    870                 if len(items) >= num:

/opt/cloudera/parcels/CDH-5.1.0-1.cdh5.1.0.p0.53/lib/spark/python/lib/py4j-0.8.1-src.zip/py4j/java_gateway.py in __call__(self, *args)
    535         answer = self.gateway_client.send_command(command)
    536         return_value = get_return_value(answer, self.gateway_client,
--> 537                 self.target_id, self.name)
    538 
    539         for temp_arg in temp_args:

/opt/cloudera/parcels/CDH-5.1.0-1.cdh5.1.0.p0.53/lib/spark/python/lib/py4j-0.8.1-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    298                 raise Py4JJavaError(
    299                     'An error occurred while calling {0}{1}{2}.\n'.
--> 300                     format(target_id, '.', name), value)
    301             else:
    302                 raise Py4JError(

Py4JJavaError: An error occurred while calling o225.collectPartitions.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 12.0:67 failed 4 times, most recent failure: Exception failure in TID 603 on host myserver715.datafireball.com: java.io.IOException: Filesystem closed
        org.apache.hadoop.hdfs.DFSClient.checkOpen(DFSClient.java:703)
        org.apache.hadoop.hdfs.DFSInputStream.readWithStrategy(DFSInputStream.java:775)
        org.apache.hadoop.hdfs.DFSInputStream.read(DFSInputStream.java:836)
        java.io.DataInputStream.read(DataInputStream.java:100)
        org.apache.hadoop.util.LineReader.fillBuffer(LineReader.java:180)
        org.apache.hadoop.util.LineReader.readDefaultLine(LineReader.java:216)
        org.apache.hadoop.util.LineReader.readLine(LineReader.java:174)
        org.apache.hadoop.mapred.LineRecordReader.next(LineRecordReader.java:246)
        org.apache.hadoop.mapred.LineRecordReader.next(LineRecordReader.java:47)
        org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:201)
        org.apache.spark.rdd.HadoopRDD$$anon$1.getNext(HadoopRDD.scala:184)
        org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:71)
        org.apache.spark.InterruptibleIterator.hasNext(InterruptibleIterator.scala:39)
        scala.collection.Iterator$$anon$11.hasNext(Iterator.scala:327)
        scala.collection.Iterator$$anon$12.hasNext(Iterator.scala:350)
        scala.collection.Iterator$class.foreach(Iterator.scala:727)
        scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
        org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:306)
        org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply$mcV$sp(PythonRDD.scala:203)
        org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:178)
        org.apache.spark.api.python.PythonRDD$WriterThread$$anonfun$run$1.apply(PythonRDD.scala:178)
        org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1160)
        org.apache.spark.api.python.PythonRDD$WriterThread.run(PythonRDD.scala:177)
Driver stacktrace:
    at org.apache.spark.scheduler.DAGScheduler.org$apache$spark$scheduler$DAGScheduler$$failJobAndIndependentStages(DAGScheduler.scala:1033)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1017)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$abortStage$1.apply(DAGScheduler.scala:1015)
    at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
    at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:47)
    at org.apache.spark.scheduler.DAGScheduler.abortStage(DAGScheduler.scala:1015)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:633)
    at org.apache.spark.scheduler.DAGScheduler$$anonfun$handleTaskSetFailed$1.apply(DAGScheduler.scala:633)
    at scala.Option.foreach(Option.scala:236)
    at org.apache.spark.scheduler.DAGScheduler.handleTaskSetFailed(DAGScheduler.scala:633)
    at org.apache.spark.scheduler.DAGSchedulerEventProcessActor$$anonfun$receive$2.applyOrElse(DAGScheduler.scala:1207)
    at akka.actor.ActorCell.receiveMessage(ActorCell.scala:498)
    at akka.actor.ActorCell.invoke(ActorCell.scala:456)
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:237)
    at akka.dispatch.Mailbox.run(Mailbox.scala:219)
    at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

Extrainfo:

We are running CDH on top of redhat boxes. As you know, Redhat use Python2.6 as the default Python version. To use iPythonnotebook, I created iPython old version to be compatible with Python2.6 on the namenode and started a iPythonnotebook using virtualenv... (For more information of how I made this sausage, click here)

This looks like a CDH error. Your code looks good (and your question is well-written - kudos). It looks like you are running CDH5.1.0-1. Have you seen this? community.cloudera.com/t5/Advanced-Analytics-Apache-Spark/… - Myles Baker
@MylesBaker Thanks for the feedback, I added some extra info at the bottom of the post about how I set up the environment to work with iPythonnotebook. See the update. - B.Mr.W.