Common operation of HBase

Keywords: HBase shell

Article directory

I. HBase Shell Operation

1.1 Basic Operations

  • Enter HBase Client
    [kino@hadoop102 hbase]$ bin/hbase shell
    
    After entering the client, backspace is the character after deleting the cursor, and ctrl + backspace is the character before deleting the cursor.
  • View Help Command
    hbase(main):001:0> help
    
    hbase(main):001:0> command help
    
  • See which tables are in the current database
    hbase(main):001:0> list
    

1.2 Table Operation

  • Create table

    # Create a table with a namespace of ns1, named t1, column family of f1, and five versions of the current column family
    hbase(main):002:0> hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
    
    # Create a table named t1 with a namespace default and specify three column families f1, f2, and f3, respectively
    hbase(main):002:0> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
    
    # Above is abbreviated as follows
    hbase(main):002:0> create 't1', 'f1', 'f2', 'f3'
    
  • View all tables

    hbase(main):002:0> list
    
  • Insert data into tables

    # Insert data into t1 table with ns1 namespace, row_key with r1, column family with c1 and value
    hbase(main):002:0> put 'ns1:t1', 'r1', 'c1', 'value'
    
    # For example:
    hbase(main):002:0> put 'student','1001','info:name','kino'
    
  • Scanning View Table Data

    # View all data in the t1 table in the namespace
    hbase(main):002:0> scan 'ns1:t1'
    
    # View the data of the specified column family in the t1 table in the namespace
    hbase(main):002:0> scan 'ns1:t1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
    
    # View the row_key in the t1 table in the namespace from STARTROW (included) to STOPROW (not included)
    hbase(main):002:0> scan 'ns1:t1', {STARTROW => '1001', STOPROW  => '1001'}
    
    # View the t1 table in the namespace, specifying n historical versions of column family n1
    hbase(main):002:0> scan 'ns1:t1', {RAW => true, VERSIONS => 10}
    
  • View data for a specified row or column family

    hbase(main):002:0> get 'ns1:t1','r1'
    	
    hbase(main):002:0> get 'ns1:t1','r1','c1'
    
  • View table structure

    hbase(main):002:0> describe 'ns1:b1'
    
  • Update data for specified fields

    hbase(main):002:0> put 'ns1:t1', 'r1', 'c1', 'value'
    	
    # For example: 
    hbase(main):002:0> put 'student','1001','info:name','Nick'
    
  • Number of rows in statistical tables

    hbase(main):002:0> count 'student'
    
  • Delete data

    • Delete all row_key data
      hbase(main):002:0> deleteall 'ns1:t1', 'r1'
      
    • Delete a column of row_key data
      hbase(main):002:0> delete 'ns1:t1', 'r1', 'c1'
      
  • Empty table data
    The order of operation for emptying the table is disable first, then truncate.

    hbase(main):002:0> truncate 'ns1:t1'
    
  • Delete table
    The table is enabled by default. To delete it, disable the table before deleting it.
    If you drop the table directly, an error will be reported: ERROR: Table student is enabled. Disable it first.

    hbase(main):002:0> disable 'ns1:t1'
    	
    	
    hbase(main):002:0> drop 'ns1:t1'
    
  • Change table information
    Store the data in the info column family in three versions:

    hbase(main):002:0> alter 'ns1:t1',{NAME=>'info',VERSIONS=>3}
    

Posted by janm2009 on Wed, 02 Oct 2019 16:32:58 -0700