Exemple #1
0
 def deletTable(self, table):
     '''
     删除hbase中的表
     :param table:表名
     :return:
     '''
     with pool.connection() as conn:
         conn.disable_table(table)
         conn.delete_table(table)
Exemple #2
0
 def batchPut(self, table):
     '''
     批量插入数据
     :param table:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         batch = t.batch(batch_size=10)
         return batch
Exemple #3
0
 def queryMultilLines(self, table, list):
     '''
     返回多行数据,返回dict
     :param table:表名
     :param list:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         return dict(t.rows(list))
Exemple #4
0
 def querySingleLine(self, table, rowkey):
     '''
     返回单行数据,返回tuple
     :param table:表名
     :param rowkey:行键
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         return t.row(rowkey)
Exemple #5
0
 def singleDelete(self, table, rowkey):
     '''
     删除单行数据
     :param table:
     :param rowkey:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         t.delete(rowkey)
Exemple #6
0
 def singlePut(self, table, rowkey, data):
     '''
     插入单条数据
     :param table:
     :param rowkey:
     :param data:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         t.put(rowkey, data=data)
Exemple #7
0
 def deleteDetailColumns(self, table, rowkey, detailColumns):
     '''
     删除一个列族中的几个列的数据
     :param table:
     :param rowkey:
     :param detailColumns:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         t.delete(rowkey, columns=detailColumns)
Exemple #8
0
 def deleteColumns(self, table, rowkey, columns):
     '''
     删除多个列族的数据
     :param table:
     :param rowkey:
     :param columns:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         t.delete(rowkey, columns=columns)
Exemple #9
0
 def batchDelete(self, table, rowkeys):
     '''
     批量删除数据
     :param table:
     :param rowkeys:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         with t.batch() as bat:
             for rowkey in rowkeys:
                 bat.delete(rowkey)
Exemple #10
0
 def truncatTable(self, table, name, families):
     '''
     清空表
     :param table:表名
     :param name:
     :param families:列簇
     :return:
     '''
     with pool.connection() as conn:
         conn.disable_table(table)
         conn.delete_table(table)
         conn.create_table(table, name, families)
Exemple #11
0
 def scanTable(self, table, row_start=None, row_stop=None, row_prefix=None):
     '''
     扫描一张表
     :param table:表名
     :param row_start:行键起
     :param row_stop:行键止
     :param row_prefix:
     :return:
     '''
     with pool.connection() as conn:
         t = happybase.Table(table, conn)
         scan = t.scan(row_start=row_start,
                       row_stop=row_stop,
                       row_prefix=row_prefix)
         for key, value in scan:
             print(key, value)