【发布时间】:2018-04-27 21:38:40
【问题描述】:
我想使用 python 从用户那里获取表名,并使用 select * 获取表的内容。下面的代码告诉我在调用 hive shell 时设置了一个变量。所以,如果是这样,这很好用一个硬编码的值。但如果我给出类似set x= $table_name 的东西,它就行不通了。这意味着它无法将 table_name 的值传递给 hive shell。
import subprocess
table_name=raw_input("enter the name of the table you want to get queried")
subprocess.call(['hive','-e','set x ="mytable";select * from ${hiveconf:x}'])
链接Python variable passed as hive query 告诉了一些方法,但不确定我将如何使用它。
【问题讨论】: