【问题标题】:Pass variables in pyspark SQL statement在 pyspark SQL 语句中传递变量
【发布时间】:2023-03-20 07:12:01
【问题描述】:

我正在尝试在 Spark SQL 语句中插入多个变量,并在此处发现了一个类似的问题: How to pass variables in spark SQL, using python? 我的问题是如何使用作为字符串变量的多个变量列表(下面的部门变量)来做到这一点?它适用于浮点数/整数。我尝试了几种语法变体,但出现“不匹配的输入 'From' 期望 EOF”错误。

configs = {"lim":10,
           "codes":"A",
           "department": " 'A', 'B', 'C'", ## this is what's not working
           "salary": "100.00, 200.00"
}

df = spark.sql("""SELECT col1, col2 from table
                  WHERE employee_id IN ({department})
AND salary IN ({salary})
                 LIMIT 10
               """.format(**configs))

【问题讨论】:

    标签: python sql apache-spark pyspark


    【解决方案1】:

    尝试转义单引号:

    "department": " \'A\', \'B\', \'C\'"

    【讨论】:

    • 您是否也尝试过双反斜杠,例如\\'A\\' 或将单引号加倍,例如''一个''
    猜你喜欢
    • 2023-03-25
    • 2014-08-22
    • 2015-08-08
    • 2021-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-28
    相关资源
    最近更新 更多