Python sparksql查询来解决这个问题

Python sparksql查询来解决这个问题,python,sql,apache-spark,pyspark,azure-databricks,Python,Sql,Apache Spark,Pyspark,Azure Databricks,所以我在Azure Databricks笔记本中运行一些脚本。 我正在使用pySpark查询表中的一些数据 query = """secret sql query""".format(ids) try: DF_sql = spark.sql(query) 查询不会提示任何错误,但我尝试将其转换为数据帧 DF_pd = DF_sql.toPandas() 但我一直在犯这样的错误: UserWarning: toPandas a

所以我在Azure Databricks笔记本中运行一些脚本。 我正在使用pySpark查询表中的一些数据

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

try:
  DF_sql = spark.sql(query)
查询不会提示任何错误,但我尝试将其转换为数据帧

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.

数据帧DF_sql可能为空,这会导致此错误吗?如果是这样,您如何优雅地处理它。

如果这是由于数据帧为空,我认为您可以检查数据帧是否为空,然后转换为数据帧

如果len(测向头(1))!=0 :
DF_pd=DF_sql.toPandas()

如果这是由于数据帧为空,我认为您可以检查数据帧是否为空,然后转换为数据帧

如果len(测向头(1))!=0 :
DF_pd=DF_sql.toPandas()

如果答案对您有帮助,您可以将其作为答案接受(单击答案旁边的复选标记,将其从灰色切换为填充)。这可能对其他社区成员有益。谢谢如果答案对您有帮助,您可以将其作为答案接受(单击答案旁边的复选标记,将其从灰色变为已填写)。这可能对其他社区成员有益。非常感谢。