6

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)
sjd
  • 1,329
  • 4
  • 28
  • 48

1 Answers1

1

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

qList = query.split(";")
for q in qList:
    cursor.execute(q)
Sharku
  • 1,052
  • 1
  • 11
  • 24
  • There are several places i m sending multiple queries in single command to save some time. I already have these codes using paramiko . trying to change to use pyhive – sjd Sep 04 '18 at 10:59
  • This answer does not seem to answer if we can still run multiple queries in one go, from pyhive. – thegreatcoder Dec 05 '19 at 16:32
  • @sharku What is your take on that? Your answer will be useful to many more people, then – thegreatcoder Dec 05 '19 at 16:33
  • @thegreatcoder I have not take on this since I never used pyhive. I just saw how to solve the problem with just python. – Sharku Dec 09 '19 at 11:52
  • you should use an actual SQL parser, in the case of embedded `;` characters. `sqlparse` works well – Neil McGuigan Jan 24 '20 at 06:11