1

嘿,我有一个 ASV(chr(1) 分隔的配置单元数据文件)格式的表。我想提取某些列,按两列的组合分组,并在每个组中做一些事情。

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

我希望输出像

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

到目前为止,我在 pyspark 中所做的事情:

错误看起来像:

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)

但它弹出如下错误消息,我不知道这是我的语法错误还是系统设置错误:

---------------------------------------------------------------------------
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)

额外信息:

我们在 redhat 盒子上运行 CDH。如您所知,Redhat 使用 Python2.6 作为默认的 Python 版本。为了使用 iPythonnotebook,我在 namenode 上创建了与 Python2.6 兼容的 iPython 旧版本,并使用 virtualenv 启动了 iPythonnotebook...(有关我如何制作此香肠的更多信息,请单击此处

4

0 回答 0