有没有一种方法可以安全地将参数传递给配置单元查询?我不想格式化查询字符串。使用mysql数据库+sqlalchemy,我可以将参数传递给数据库连接,引擎会为我做这件事。我想做一些像下面这样的事情。但是 client.execute
函数不接受参数。我正在运行hive0.10.0。
from datetime import date
from hive_service import ThriftHive
from hive_service.ttypes import HiveServerException
from thrift.transport import TSocket, TTransport
from thrift.protocol import TBinaryProtocol
transport = TSocket.TSocket(settings.HIVE_SERVER, settings.HIVE_PORT)
transport = TTransport.TBufferedTransport(transport)
protocol = TBinaryProtocol.TBinaryProtocol(transport)
client = ThriftHive.Client(protocol)
transport.open()
q = """
select *
from tbl
where dt = %(query_date)s
limit 10
"""
params = {'query_date':date(2016,1,1)}
client.execute(q, params)
results = client.fetchAll()
暂无答案!
目前还没有任何答案,快来回答吧!