HBAse共通コマンド


HBAseの一般的な基礎知識
1.hbaseでよく使用されるshellコマンド
// An highlighted block

## HBase      namespace:
list_namespace

##  namespace
create_namespace "test"

##    namespace 
drop_namespace 'test_ns'

##    namespace    
list_namespace_tables 'dingtalk'

##    namespace  
describe_namespace "dingtalk"

##    namespace      
scan 'dingtalk:website'

##          
count 'dingtalk:website'

##          mapreduce    
$HBASE_HOME/bin/hbase org.apache.hadoop.hbase.mapreduce.RowCounter 'HtableName'

##      :
desc 'dingtalk:website'

##   rowKey    
get 'dingtalk:website','b9cb51e146794ffba8d838335ca300fb'

get 'dingtalk:website','b9cb51e146794ffba8d838335ca300fb',{
     FORMATTER=>'toString'}

##   rowKey         
get 'my_test','0011','info:ch:toString'

##      : hbase    disable ,  drop        truncate    
truncate 'dingtalk:website' 

##   hbase 
disable 'dingtalk:website'

##   hbase 
enable  'dingtalk:website'

#      
alter 'dingtalk:website', NAME => 'info', VERSIONS => 9999

##   hbase 
drop 'dingtalk:website'


##      enable:
is_enabled 'dingtalk:website'

##      disable:
is_disabled 'dingtalk:website'

##        region
create 'dingtalk:website',{
     NAME=>'info',VERSIONS=>3, TTL => 2592000,COMPRESSION => 'SNAPPY'},{
     NUMREGIONS=>10,SPLITALGO=>'HexStringSplit',REGION_REPLICATION=>2,MIN_VERSIONS => '0'}

##        region
create 'dingtalk:website1',{
     NAME=>'info',VERSIONS=>3,BLOCKCACHE=>true,BLOOMFILTER=>'ROW',COMPRESSION=>'SNAPPY'},{
     SPLITS => ['20','40','60','80']}

##      enable:
flush 'dingtalk:website'


disable 'table'

enable 'table'

##      
alter 'dingtalk:trade_mark', NAME => 'info', VERSIONS => 9999

##   5   
scan 'dingtalk:patent',{
     FORMATTER=>'toString',LIMIT=>5}

##        
scan 'dingtalk:patent',{
     FORMATTER=>'toString',LIMIT=>5,COLUMNS=>['info:name','info:age']}

##   scan   rowkey    
scan 'dingtalk:patent',{
     ROWPREFIXFILTER=>'0151099104887566931',FORMATTER=>'toString',LIMIT=>5,COLUMNS=>['info:name','info:age']}

##     
scan 'dingtalk:patent',{
     FILTER=>"PrefixFilter('0151099104887566931')"}

##     
scan 'dingtalk:patent',{
     STARTROW=>'7CN2103801',STOPROW=>'7CN2103802'}


##      
scan 'dingtalk:patent',{
     FILTER=>"SingleColumnValueFilter('info','name',=,'binary:  ')",FORMATTER=>'toString'}


##       
scan 'dingtalk:patent',{
     FILTER=>"SingleColumnValueFilter('info','name',=,'binary:  2') AND SingleColumnValueFilter('info','age',>,'binary:18')",FORMATTER=>'toString'}


##     
put 'test:user_info','001001001','F1:real_name','  HBase' 


##    user_info COLUMNS=F1  10   
scan 'test:user_info',{
     COLUMNS=>'F1',LIMIT=>5}

##    user_info      5     
scan 'test:user_info',{
     VERSIONS=>5}

##                  
scan 'my_test',{
     RAW=>TRUE,VERSIONS=>2}


##    user_info rowkey=00200000011’,column=F1:address’   
delete 'test:user_info','00200000011','F1:address'

##      (deleteall)
deleteall 'test:user_info','00200000011'

##         (truncate)       :disable table -> drop table -> create table
truncate 'test:user_info'


#    
create 'test:user_info','c2'

#    
create 'test:user_info','c2'

##   
1)        list_snapshots
2)         list_table_snapshots
3)      snapshot 'test:user_info', 'snapshot.user_info.20190726'
4)     delete_snapshot 'snapshot.user_info.20190726'

##  shell    hbase  
hbase shell /export/software/hbaseScript.rb


2. hbase bulkload
// A code block
## 1)  csv      hfile  
hbase org.apache.hadoop.hbase.mapreduce.ImportTsv \
'-Dimporttsv.separator=,' \
-Dimporttsv.bulk.output=/tmp/test/hfile \
-Dimporttsv.columns=HBASE_ROW_KEY,info:en,info:ch my_test /tmp/test/test.tsv


## 2) hfile        hbase
HADOOP_CLASSPATH=`/opt/cloudera/parcels/CDH-6.3.2-1.cdh6.3.2.p0.1605554/lib/hbase/bin/hbase mapredcp` \
hadoop jar /opt/cloudera/parcels/CDH/lib/hbase/hbase-mapreduce.jar \
completebulkload /tmp/test/hfile default:my_test


3.hiveマッピングHbase
CREATE external TABLE `hbase_website`(
  `key` string, 
  `ocid` string, 
  `companyname` string, 
  `createtime` bigint, 
  `updatetime` bigint, 
  `sitename` string, 
  `number` string, 
  `homeurl` string, 
  `checkdate` string, 
  `domain` string)
  STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'    
WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,info:ocid,info:companyname,info:createtime,info:updatetime,info:sitename,info:number,info:homeurl,info:checkdate,info:domain")    
TBLPROPERTIES("hbase.table.name" = "dingtalk:website");