封装一下 pyhs2,让其使用起来和 torndb 一样简单好用。
提供 db.query、db.get、db.execute 三个方法,用法和 torndb 完全一样。
query 和 get 返回值数据类型也完全一样; 惟一不同的是 execute 方法,torndb 中会返回 lastrowid,本文中返回 None
# coding: u8
import pyhs2
from pyhs2.error import Pyhs2Exception
class Row(dict):
"""A dict that allows for object-like property access syntax."""
def __getattr__(self, name):
try:
return self[name]
except KeyError:
raise AttributeError(name)
class Connection(object):
def __init__(self, db_host, user, database, port=10000,
authMechanism="PLAIN"):
"""
create connection to hive server2
"""
self.conn = pyhs2.connect(host=db_host,
port=port,
authMechanism=authMechanism,
user=user,
d