在单个pyhive.execute命令中执行多个查询

时间:2018-09-04 06:50:01

标签: python pyhive

使用pyhive,是否可以执行多个hql,例如“ CREATE TABLE TABLE1(ITEM_KEY BIGINT); CREATE TABLE TABLE2(ITEM_NAME BIGINT);”。

示例代码

from pyhive import hive
conn = hive.Connection(host=host
                       , port=port, username=user
                       , password=passwd
                       , auth=auth)
cursor = conn.cursor()
query= 'CREATE TABLE TABLE1 (ITEM_KEY BIGINT );CREATE TABLE TABLE2 (ITEM_NAME BIGINT );'. 
cursor.execute(query)

1 个答案:

答案 0 :(得分:2)

如何拆分查询并一一执行呢?

qList = query.split(";")
for q in qList:
    cursor.execute(q)
相关问题