【问题标题】:AttributeError: 'SparkSession' object has no attribute 'time'AttributeError:“SparkSession”对象没有属性“时间”
【发布时间】:2019-05-17 03:09:49
【问题描述】:

我正在执行一个 SQL 查询,并希望能够打印出执行该查询需要多长时间。我不断收到一个属性错误,说 Spark Session 没有属性时间。我一直在做以下事情:

>>> df2 = sqlContext.sql("select * from temptable where Location == 'Moorland Rd Library'")
>>> spark.time(df2.show())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SparkSession' object has no attribute 'time'

【问题讨论】:

  • 我假设您的代码中某处是from apachespark import SparkSession as spark
  • @TheIncorrigible1 已经做到了,但仍然无法正常工作:from pyspark.sql import SparkSession as spark

标签: python sql apache-spark pyspark


【解决方案1】:

SparkSession.time() 函数仅在 scala 中可用。对于 python,您可以改用 time 模块。

import time
time(df2.show())

【讨论】:

    【解决方案2】:

    就像其他人提到的那样,SparkSession.time() 它在 pyspark 中不可用。一个简单的解决方案是使用time:

    import time
    start_time = time.time()
    df2.show()
    print(f"Execution time: {time.time() - start_time}")
    

    【讨论】:

      猜你喜欢
      • 2017-01-24
      • 1970-01-01
      • 1970-01-01
      • 2020-05-19
      • 1970-01-01
      • 2017-01-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多