Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute multiple queries in single pyhive.execute command

Tags:

python

pyhive

Using pyhive, is it possible to execute multiple hql's like 'CREATE TABLE TABLE1 (ITEM_KEY BIGINT );CREATE TABLE TABLE2 (ITEM_NAME BIGINT );'.

Sample code

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)
like image 549
sjd Avatar asked Nov 07 '22 02:11

sjd


1 Answers

How about you split your query and execute them one by one?

qList = query.split(";")
for q in qList:
    cursor.execute(q)
like image 116
Sharku Avatar answered Nov 14 '22 21:11

Sharku