hbase命令使用记录

使用自带MR将一个集群上hbase的表导入另一个集群上hbase表中:

1、使用 hbase org.apache.hadoop.hbase.mapreduce.Driver export t_can_20190205 hdfs:///tmp/t_can_20190205  命令将hbase表导入到hdfs中文件中

2、将导入hdfs的文件下载下来后再上传到另一个集群的hdfs上

3、在目前集群的hbase上建表,建表的结构和之前hbase表结构一致

4、使用 hbase org.apache.hadoop.hbase.mapreduce.Driver import t_can_20190205 hdfs:///user/t_can_20190205 命令将hdfs数据导入hbase表中

 注意使用参数的方式:

  -D hbase.mapreduce.scan.row.start=<ROWSTART>
  -D hbase.mapreduce.scan.row.stop=<ROWSTOP>
  Export [-D <property=value>]* <tablename> <outputdir> [<versions> [<starttime> [<endtime>]] [^[regex pattern] or [Prefix] to filter]]
  hbase org.apache.hadoop.hbase.mapreduce.Driver export -D hbase.mapreduce.scan.row.start=0 -D hbase.mapreduce.scan.row.stop=1000?* t_gps_sq_20190424 hdfs:///tmp/t_gps_sq_20190424_
  hbase org.apache.hadoop.hbase.mapreduce.Driver export -D hbase.mapreduce.scan.row.start=xADx5CxACxF6w -D hbase.mapreduce.scan.row.stop=xADx5CxAD1xFF?* t_gps_sq_20190424 hdfs:///tmp/t_gps_sq_20190424___

统计表中数据个数(4种方式):

1.hbase shell中执行count的命令:

    count ‘t1′, INTERVAL => 10, CACHE => 1000     

    INTERVAL为统计的行数间隔,默认为1000,CACHE为统计的数据缓存。这种方式效率很低,如果表行数很大的话不建议采用这种方式。

2.Hbase自带 mapreduce 工具类:

  使用自带MR的命令: hbase   org.apache.hadoop.hbase.mapreduce.RowCounter ‘tablename’

3.使用 coprocessor 新特性,编写如下代码执行:

Configuration conf = HBaseConfiguration.create();
HTable hTable = new HTable(conf, TableName.valueOf("T_REVIEW_MODULE"));
LongColumnInterpreter columnInterpreter = new LongColumnInterpreter();
AggregationClient aggregationClient = new AggregationClient(conf);
Scan scan = new Scan( Bytes.toBytes("startRow"), Bytes.toBytes("stopRow"));
Long count = aggregationClient.rowCount(hTable, columnInterpreter, scan);

4.hive over hbase:用hive的语句创建hbase的关联表,可以直接在hive中执行sql语句统计hbase表的行数。创建关联表的语句:

CREATE TABLE hive_hbase_1(key INT,value STRING)  
STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'  
WITH SERDEPROPERTIES ("hbase.columns.mapping"=":key,cf:val")  
TBLPROPERTIES("hbase.table.name"="t_hive","hbase.table.default.storage.type"="binary");  
原文地址:https://www.cnblogs.com/zyanrong/p/10951457.html