Search code examples
hadoophbase

Put values inside multiple columns in same family in Hbase


I am looking for a Hbase put command that can insert values into multiple columns in same column family for a same rowkey in Hbase table. Let's say I have a hbase table named 'employee' with 1 column family 'data'

I am applying below command but it throws error.

PUT 'employee' 'data:column1', 'column1_val', 'data:column2', 'column_val2'
ERROR: no method 'add' for arguments (org.jruby.java.proxies.ArrayJavaProxy,org.jruby.RubyNil,org.jruby.RubyString,org.jruby.java.proxies.ArrayJavaProxy) on Java::OrgApacheHadoopHbaseClient::Put available overloads:

However if i try separate put commands for each column value insertion, it works fine.

PUT 'employee' 'data:column1', 'column1_val'
PUT 'employee' 'data:column2', 'column2_val'

Is there a way to insert values into multiple columns belonging to same column family in a single put command?


Solution

  • HBase shell does not support multiple columns in one statement

    hbase(main):002:0> help "put"
    Put a cell 'value' at specified table/row/column and optionally
    timestamp coordinates.  To put a cell value into table 'ns1:t1' or 't1'
    at row 'r1' under column 'c1' marked with the time 'ts1', do:
    
      hbase> put 'ns1:t1', 'r1', 'c1', 'value'
      hbase> put 't1', 'r1', 'c1', 'value'
      hbase> put 't1', 'r1', 'c1', 'value', ts1
      hbase> put 't1', 'r1', 'c1', 'value', {ATTRIBUTES=>{'mykey'=>'myvalue'}}
      hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
      hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
    
    The same commands also can be run on a table reference. Suppose you had a reference
    t to table 't1', the corresponding command would be:
    
      hbase> t.put 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}}
    

    You can create multiple puts with same timestamps though, it is fine.