问题:使用sqlalchemy连接hive进行创建表操作,当数据表已经存在时会报错,但无法获取具体信息
解决:使用try except捕捉异常信息
方法:
try:
session.execute(sql)
except Exception as e:
code = e.code
tstatus = e.orig.args[0].status
msg = tstatus.errorMessage
问题:使用sqlalchemy连接hive进行创建表操作,当数据表已经存在时会报错,但无法获取具体信息
解决:使用try except捕捉异常信息
方法:
try:
session.execute(sql)
except Exception as e:
code = e.code
tstatus = e.orig.args[0].status
msg = tstatus.errorMessage
问题:使用datagrip查看hive表时,发现表的注释乱码,如何解决?
解决:修改hive元数据表COLUMNS_V2中COMMENT字段编码为utf8,修改hive-site.xml连接方式
方法:
1、修改hive元数据库
// 解决列名注释乱码
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
// 解决表名注释乱码
alter table TABLE_PARAMS modify column PARAM_VALUE MEDIUMTEXT character set utf8;
问题:使用pyhive连接后使用pandas会预警,让使用sqlalchemy
方法:
from sqlalchemy.engine import create_engine
from .config import config
database_config = {
'host': config['HV_SVR'],
'port': 10000,
'auth': "CUSTOM",
'database': config['HV_DB'],
'user': config['HV_USER'],
'password': config['HV_PASS']
}
问题:python如何连接hive数据仓库?
解决:使用pyhive
方法:
1、安装三个python包,网上有的说要安装sasl,但我没安装成功,然后发现不安装也可以
pip install thrift==0.20.0 thrift-sasl==0.4.3 pyhive==0.7.0
问题:使用pyhive连接hive数据库时报错
解决:可能因为hive未启动
方法:
1、启动hdfs、yarn
2、启动hiveserver2
3、确保连接写的成功
conn = hive.Connection(
host=qy_host,
port=10000,
auth=“CUSTOM”,
database=‘default’,
username=qy_user,
password=qy_pw)
hive_cur = hive_conn.cursor()