(Spark 和)Databricks 中的下推查询不适用于“with 语句”?

问题描述 投票:0回答:1

我是 Azure databricks 的新手,所以希望我的问题不会太离谱。我正在尝试在 Azure databricks 笔记本中运行 sql 下推查询,但使用“with 语句”,但它不起作用。我尝试了类似的下推查询,但没有成功:

sql = """
        with r as (select max(load_id) as load_id, table_name
        from LOG.TABLE_AND_FILE_ACQUISITION_MONITORING
        group by TABLE_NAME)
        (select * from r) t"""
sql = """
        (with r as (select max(load_id) as load_id, table_name
        from LOG.TABLE_AND_FILE_ACQUISITION_MONITORING
        group by TABLE_NAME)
        select * from r) t"""

运行此命令后:

df = spark.read.jdbc(url=jdbc_url, table=sql, properties=connection_properties)
display(df)

我收到此错误:关键字“with”附近的语法不正确。 有人可以知道如何使其工作的语法吗? 谢谢!


apache-spark jdbc databricks
1个回答
0
投票

这应该是正确的语法:

sql = """
        with r as (select max(load_id) as load_id, table_name
        from LOG.TABLE_AND_FILE_ACQUISITION_MONITORING
        group by TABLE_NAME)
        select * from r"""
© www.soinside.com 2019 - 2024. All rights reserved.