使用impyla执行时如何在配置单元查询中传递参数?

xu3bshqb  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(351)

我提到了如何在python的sql语句中使用变量?
但却找不到答案。
我在试你的建议,但我得到了这个错误-:(

tbl_nm = 'EMPLOYEE_TABLE'

con.execute('select max(emp_id) from schema.?', tbl_nm)

获取以下错误:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 302,

in execute configuration=configuration) File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 343,

in execute_async self._execute_async(op) File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 362,

in _execute_async operation_fn() File "/usr/local/lib/python2.7/site-packages/impala/hiveserver2.py", line 334,

in op parameters) File "/usr/local/lib/python2.7/site-packages/impala/interface.py", line 267,

in _bind_parameters

raise ProgrammingError("Query parameters argument should be a "
impala.error.ProgrammingError: Query parameters argument should be a list, tuple, or dict object

>
b5lpy0ml

b5lpy0ml1#

建议您将查询作为字符串存储到变量中,并将其传递给execute方法,而不是直接将原始配置单元查询传递给execute方法。
就你而言:

tbl_nm = 'EMPLOYEE_TABLE'
query = "select max(emp_id) from schema.{}".format(tbl_nm)
con.execute(query)

如果这有帮助,请告诉我。

相关问题