【问题标题】:Pyhive Presto insert select * from not runningPyhive Presto insert select * from not running
【发布时间】:2023-03-13 00:20:01
【问题描述】:

我可以使用 PYHIVE 连接到 PRESTO 并选择数据回来就好了。我正在尝试使用 PYHIVE 在 presto 上运行“insert into x select from y”,但它没有运行。我确定我错过了一些简单的东西。

from pyhive import presto
import requests
from requests.auth import HTTPBasicAuth
import pandas as pd

req_kw = {'auth': HTTPBasicAuth(user, pw),'verify':False}

conn = presto.connect(host=ht,port=prt,protocol='https',catalog='hive',username=user,requests_kwargs=req_kw)

cursor  = conn.cursor()

query='select count(1) from dim.date_dim '
cursor.execute(query)
print(cursor.fetchall())

query='insert into flowersc.date_dim select * from dim.date_dim'
cursor.execute(query)

query='select count(1) from flowersc.date_dim '
cursor.execute(query)
print(cursor.fetchall())

没有错误发生

但结果显示没有加载数据

[(16624,)] [(0,)]

非常感谢任何帮助。

【问题讨论】:

  • flowersc.date_dim位置有数据吗?

标签: python presto pyhive


【解决方案1】:

您需要检查(获取)结果

query='insert into flowersc.date_dim select * from dim.date_dim'
cursor.execute(query).next() # added .next()

这是必要的,因为 Presto 在 2018 年 5 月发生了变化 (https://github.com/prestosql/presto/commit/568449b8d058ed8281cc5277bb53902fd044cad7)。但验证查询结果也是一个好习惯,即检查您的INSERT 语句是否成功。

【讨论】:

  • 感谢您的回复,但它没有因错误而失败。
  • from pyhive import presto import requests from requests.auth import HTTPBasicAuth import pandas as pd req_kw = {'auth': HTTPBasicAuth(user, pw),'verify':False} conn = presto.connect( host=ht,port=prt,protocol='https',catalog='hive',username=user,requests_kwargs=req_kw) cursor = conn.cursor() query='select count(1) from dim.date_dim' 光标。 execute(query) print(cursor.fetchall()) query='insert into flowersc.date_dim select * from dim.date_dim' cursor.execute(query).fetchall() query='select count(1) from flowersc.date_dim' cursor.execute(query) print(cursor.fetchall())
  • ------------------------------------------ --------------------------------- AttributeError Traceback(最近一次调用最后一次) 11 12 query='insert into flowersc.date_dim select * from dim.date_dim' ---> 13 cursor.execute(query).fetchall() 14 15 query='select count(1) from flowersc.date_dim ' AttributeError: 'NoneType' 对象没有属性 'fetchall'
  • 我想通了。我使用了 next() 方法。
猜你喜欢
  • 2016-06-05
  • 1970-01-01
  • 2022-08-02
  • 2018-02-27
  • 2020-07-13
  • 2011-01-29
  • 2015-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多