sparksql查询

pxyaymoc  于 2021-05-27  发布在  Spark
关注(0)|答案(1)|浏览(483)

所以我在azuredatabricks笔记本上运行一些脚本。我正在使用pyspark查询表中的一些数据。

query = """secret sql query""".format(ids)

try:
  DF_sql = spark.sql(query)

查询不会提示任何错误,但我尝试将其转换为Dataframe

DF_pd = DF_sql.toPandas()

但我一直有个错误:

UserWarning: toPandas attempted Arrow optimization because 'spark.sql.execution.arrow.enabled' is set to true, but has reached the error below and can not continue. Note that 'spark.sql.execution.arrow.fallback.enabled' does not have an effect on failures in the middle of computation.

dataframe df\u sql可能为空,这会导致此错误吗?如果是这样的话,你该如何优雅地处理。

0yycz8jy

0yycz8jy1#

如果这是由于空dataframe造成的,我认为您可以检查dataframe是否为空,然后转换为dataframe。
如果长度(测向头(1))!=0:df\u pd=df\u sql.topandas()

相关问题