首页 文章

PySpark groupBy计数失败,显示方法

提问于
浏览
1

我的 df 运行Spark 2.1.0时遇到问题,它有几个字符串列作为来自Hive DB的SQL查询创建,它给出了 .summary()

DataFrame[summary: string, visitorid: string, eventtype: string, ..., target: string] .

如果我只运行 df.groupBy("eventtype").count() ,它可以工作,我得 DataFrame[eventtype: string, count: bigint]

当使用show df.groupBy('eventtype').count().show() 运行时,我会继续:

Traceback (most recent call last):
  File "/tmp/zeppelin_pyspark-9040214714346906648.py", line 267, in <module>
    raise Exception(traceback.format_exc())
Exception: Traceback (most recent call last):
  File "/tmp/zeppelin_pyspark-9040214714346906648.py", line 265, in <module>
    exec(code)
  File "<stdin>", line 1, in <module>
  File "/usr/lib/spark/python/pyspark/sql/dataframe.py", line 318, in show
    print(self._jdf.showString(n, 20))
  File "/usr/lib/spark/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py", line 1133, in __call__
    answer, self.gateway_client, self.target_id, self.name)
  File "/usr/lib/spark/python/pyspark/sql/utils.py", line 63, in deco
    return f(*a, **kw)
  File "/usr/lib/spark/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py", line 319, in get_return_value
    format(target_id, ".", name), value)

Py4JJavaError: An error occurred while calling o4636.showString.
: org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 633.0 failed 4 times, most recent failure: Lost task 0.3 in stage 633.0 (TID 19944, ip-172-31-28-173.eu-west-1.compute.internal, executor 440): java.lang.NullPointerException

我不知道show方法有什么问题(其他列都不起作用,而不是我创建的事件列 target ) . 群集的管理员也无法帮助我 .

非常感谢任何指针

2 回答

  • 0

    存在一些问题,目前我们知道您的DataFrame包含一些限制的问题 . 如果是的话,你可能会进入https://issues.apache.org/jira/browse/SPARK-18528

    这意味着,您必须将Spark版本升级到2.1.1,或者您可以使用 repartition 作为解决方法来避免此问题

    正如@AssafMendelson所说,count()只创建新的DataFrame,但它不会开始计算 . 执行show或ie head将开始计算 .

    如果Jira机票和升级对您没有帮助,请发布工作日志

  • 0

    当你跑步

    df.groupBy("eventtype").count()
    

    您实际上是在HOW上定义一个惰性转换来计算结果 . 无论数据大小如何,这都会立即返回一个新的数据帧 . 当您调用show时,您正在执行操作,这是实际计算开始的时间 .

    如果查看错误日志的底部:

    org.apache.spark.SparkException: Job aborted due to stage failure: Task 0 in stage 633.0 failed 4 times, most recent failure: Lost task 0.3 in stage 633.0 (TID 19944, ip-172-31-28-173.eu-west-1.compute.internal, executor 440): java.lang.NullPointerException
    

    您可以看到其中一个任务由于空指针异常而失败 . 我会去检查df的定义以查看之前发生的事情(甚至可以看看是否只是做df.count()会导致异常) .

相关问题