有没有一种方法可以将参数安全地传递给配置单元查询?我不想格式化查询字符串。使用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()
目前没有回答
相关问题 更多 >
编程相关推荐