本文整理汇总了Python中happybase.Connection方法的典型用法代码示例。如果您正苦于以下问题:Python happybase.Connection方法的具体用法?Python happybase.Connection怎么用?Python happybase.Connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类happybase
的用法示例。
在下文中一共展示了happybase.Connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: insert
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def insert(table_name, key, data, timestamp):
connection = happybase.Connection(setting.HBASE_HOST, port=setting.HBASE_PORT)
table = connection.table(table_name)
table.put(key, data, timestamp)
connection.close()
示例2: setup_module
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def setup_module():
global connection, table
connection = Connection(**connection_kwargs)
assert_is_not_none(connection)
maybe_delete_table()
cfs = {
'cf1': {},
'cf2': None,
'cf3': {'max_versions': 1},
}
connection.create_table(TEST_TABLE_NAME, families=cfs)
table = connection.table(TEST_TABLE_NAME)
assert_is_not_none(table)
示例3: session_create
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def session_create(self, db_name=None):
try:
"""
Hbase Loader Class
creadted for the purpose of handling Spark Jobs
"""
tfmsa_logger("Hbase Session Created")
if db_name is None:
conn = happybase.Connection(host=settings.HBASE_HOST, port=settings.HBASE_HOST_PORT, )
if db_name is not None:
conn = happybase.Connection(host=settings.HBASE_HOST, port=settings.HBASE_HOST_PORT, table_prefix=db_name, table_prefix_separator=':')
return conn
except Exception as e:
tfmsa_logger("Error : {0}".format(e))
raise Exception(e)
示例4: __new__
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def __new__(cls, host='localhost', port=9090, *args, **kwargs):
if not cls.__instance:
try:
Lock.acquire()
if not cls.__instance:
cls.__instance = super(HappyBaseConnection, cls).__new__(cls, *args, **kwargs)
hb = happybase.Connection(host=host, port=port)
hb.open()
setattr(cls.__instance, 'hb', hb)
print('???????')
finally:
Lock.release()
return cls.__instance
示例5: get_client_profile
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def get_client_profile(self, client_id):
"""Retrieve the latest row for the given client in HBase
Only the last known version of the info is retrieved"""
try:
with contextlib.closing(Connection(self.hbase_hostname)) as connection:
table = connection.table(self.tablename)
client_row = table.row(client_id, columns=[self.column_family])
if client_row:
return json.loads(client_row[self.column].decode("utf-8"))
except Exception:
logger.exception("Connection to HBase failed", extra={"client_id": client_id})
logger.info("Client information not found", extra={"client_id": client_id})
return None
示例6: main
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def main():
HOST='hbase-docker'
PORT=9090
# Will create and then delete this table
TABLE_NAME='table-name'
ROW_KEY='row-key'
connection = happybase.Connection(HOST, PORT)
tables = connection.tables()
print "HBase has tables {0}".format(tables)
if TABLE_NAME not in tables:
print "Creating table {0}".format(TABLE_NAME)
connection.create_table(TABLE_NAME, { 'family': dict() } )
table = connection.table(TABLE_NAME)
print "Storing values with row key '{0}'".format(ROW_KEY)
table.put(ROW_KEY, {'family:qual1': 'value1',
'family:qual2': 'value2'})
print "Getting values for row key '{0}'".format(ROW_KEY)
row = table.row(ROW_KEY)
print row['family:qual1']
print "Printing rows with keys '{0}' and row-key-2".format(ROW_KEY)
for key, data in table.rows([ROW_KEY, 'row-key-2']):
print key, data
print "Scanning rows with prefix 'row'"
for key, data in table.scan(row_prefix='row'):
print key, data # prints 'value1' and 'value2'
print "Deleting row '{0}'".format(ROW_KEY)
row = table.delete(ROW_KEY)
print "Deleting table {0}".format(TABLE_NAME)
connection.delete_table(TABLE_NAME, disable=True)
示例7: __init__
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def __init__(self, hbase_host):
"""
???,??hbase
:param hbasehost: ???? (str)
:return: None
"""
try:
self.connection = happybase.Connection(hbase_host)
except Exception, e:
print e
示例8: connectToHBase
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def connectToHBase():
conn = happybase.Connection(host = host,\
table_prefix = namespace,\
table_prefix_separator = ":")
conn.open()
table = conn.table(table_name)
batch = table.batch(batch_size = batch_size)
return conn, batch
示例9: __init__
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def __init__(self, setting):
self.backlog_count_ = 0
self.backlog_upper_bound_ = 20
self.table_ = None
self.batch_ = None
self.batch_size_ = int(setting.get('batch_size'))
self.connection_ = happybase.Connection(
host=setting['host'],
table_prefix=setting['namespace'],
table_prefix_separator=setting['namespace_separator'],
autoconnect=False)
示例10: drop_table
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def drop_table(table_name):
connection = happybase.Connection(setting.HBASE_HOST, port=setting.HBASE_PORT)
connection.disable_table(table_name)
connection.delete_table(table_name)
connection.close()
示例11: create_table
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def create_table(table_name, table_families):
connection = happybase.Connection(setting.HBASE_HOST, port=setting.HBASE_PORT)
connection.create_table(table_name, families=table_families)
connection.close()
示例12: scan
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def scan(table_name):
connection = happybase.Connection(setting.HBASE_HOST, port=setting.HBASE_PORT)
table = connection.table(table_name)
items = table.scan()
for item in items:
print json.dumps(dict(item[1])).decode('unicode-escape')
print(len(list(items)))
connection.close()
示例13: write_csv
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def write_csv(table_name, file_name, key_filter='2016'):
connection = happybase.Connection(setting.HBASE_HOST, port=setting.HBASE_PORT)
table = connection.table(table_name)
items = table.scan(filter="RowFilter(=,\'substring:%s\')" % (key_filter,))
with open(file_name, 'wb') as csvfile:
csvfile.write(codecs.BOM_UTF8)
spamwriter = csv.writer(csvfile, dialect='excel')
i = 0
for item in items:
if i == 0:
temp_dict = dict(item[1]).keys()
temp_dict.append('key')
spamwriter.writerow(temp_dict)
temp_dict = dict(item[1]).values()
temp_dict.append(item[0])
spamwriter.writerow(temp_dict)
i += 1
connection.close()
# write_csv('index', 'data.csv', '201610')
# scan('index')
# drop_table('index')
# create_table('index', {'fam_exponent_info': dict(max_versions=31),
# 'fam_baidu': dict(max_versions=31),
# 'fam_ali': dict(max_versions=31),
# })
示例14: test_connection_compat
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def test_connection_compat():
with assert_raises(ValueError):
Connection(compat='0.1.invalid.version')
示例15: test_timeout_arg
# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def test_timeout_arg():
Connection(
timeout=5000,
autoconnect=False)