当前位置: 首页>>代码示例>>Python>>正文


Python happybase.Connection方法代码示例

本文整理汇总了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() 
开发者ID:DarkSand,项目名称:Spider_index,代码行数:7,代码来源:hbase_module.py

示例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) 
开发者ID:openstack,项目名称:deb-python-happybase,代码行数:18,代码来源:test_api.py

示例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) 
开发者ID:TensorMSA,项目名称:tensormsa_old,代码行数:18,代码来源:hbase_manager.py

示例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 
开发者ID:thsheep,项目名称:Python_Study,代码行数:15,代码来源:hbaseconnection_test.py

示例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 
开发者ID:mozilla,项目名称:taar,代码行数:17,代码来源:hbase_client.py

示例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) 
开发者ID:casertap,项目名称:frontera-google-docker,代码行数:42,代码来源:test_hbase.py

示例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 
开发者ID:w4n9H,项目名称:PythonSkillTree,代码行数:12,代码来源:HbaseClient.py

示例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 
开发者ID:rafacheng,项目名称:Douban_Crawler,代码行数:10,代码来源:process_review_items.py

示例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) 
开发者ID:rafacheng,项目名称:Douban_Crawler,代码行数:15,代码来源:hbase_instance.py

示例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() 
开发者ID:DarkSand,项目名称:Spider_index,代码行数:7,代码来源:hbase_module.py

示例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() 
开发者ID:DarkSand,项目名称:Spider_index,代码行数:6,代码来源:hbase_module.py

示例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() 
开发者ID:DarkSand,项目名称:Spider_index,代码行数:10,代码来源:hbase_module.py

示例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),
#                        }) 
开发者ID:DarkSand,项目名称:Spider_index,代码行数:32,代码来源:hbase_module.py

示例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') 
开发者ID:openstack,项目名称:deb-python-happybase,代码行数:5,代码来源:test_api.py

示例15: test_timeout_arg

# 需要导入模块: import happybase [as 别名]
# 或者: from happybase import Connection [as 别名]
def test_timeout_arg():
    Connection(
        timeout=5000,
        autoconnect=False) 
开发者ID:openstack,项目名称:deb-python-happybase,代码行数:6,代码来源:test_api.py


注:本文中的happybase.Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。