Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么我在使用sqlalchemy hive时出错?_Python_Hive_Sqlalchemy - Fatal编程技术网

Python 为什么我在使用sqlalchemy hive时出错?

Python 为什么我在使用sqlalchemy hive时出错?,python,hive,sqlalchemy,Python,Hive,Sqlalchemy,这是我保存到配置单元表的数据帧代码 但是当我运行代码时,我得到了如下错误消息 import pandas as pd from sqlalchemy import create_engine host='user@127.0.0.1' port=10000 schema ='result' table='new_table' engine = create_engine(f'hive://{host}:{port}/{schema}') conn=engine.connect() engi

这是我保存到配置单元表的数据帧代码

但是当我运行代码时,我得到了如下错误消息

import pandas as pd
from sqlalchemy import create_engine


host='user@127.0.0.1'
port=10000
schema ='result'
table='new_table'

engine = create_engine(f'hive://{host}:{port}/{schema}')
conn=engine.connect()
engine.execute('CREATE TABLE ' + table + ' (year int, GDP_rate int, GDP string)')
data = {
'year': [2017, 2018],
'GDP_rate': [31, 30],
'GDP': ['1.73M', '1.83M']
}

df = pd.DataFrame(data)
df.to_sql(name=table, con=engine,schema='result',index=False,if_exists='append',chunksize=5000)

conn.close()
实际上,我不知道为什么,结果只有一个数据帧保存在配置单元表中

如果有人知道原因,请告诉我
谢谢你

一个可能的pyhive bug。看见插入多行时会出现问题。

请为批量插入添加方法class='multi'


df.to_sql(“table_name”,con=engine,index=False,method='multi')

我认为这个方法很有效。
File "/opt/rh/rh-python36/root/usr/lib/python3.6/site-packages/pyhive/hive.py", line 380, in _fetch_more
raise ProgrammingError("No result set")
sqlalchemy.exc.ProgrammingError: (pyhive.exc.ProgrammingError) No result set
[SQL: INSERT INTO TABLE `result`.`new_table` VALUES (%(year)s, %(GDP_rate)s, %(GDP)s)]
[parameters: ({'year': 2017, 'GDP_rate': 31, 'GDP': '1.73M'}, {'year': 2018, 'GDP_rate': 30, 'GDP': 
'1.83M'})]
(Background on this error at: http://sqlalche.me/e/f405)