當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。