diff --git hbase-shell/src/main/ruby/hbase/table.rb hbase-shell/src/main/ruby/hbase/table.rb index 13d7646..e6984ca 100644 --- hbase-shell/src/main/ruby/hbase/table.rb +++ hbase-shell/src/main/ruby/hbase/table.rb @@ -127,7 +127,7 @@ EOF # they will be much less likely to tab complete to the 'dangerous' internal method #---------------------------------------------------------------------------------------------- # Put a cell 'value' at specified table/row/column - def _put_internal(row, column, value, timestamp = nil) + def _put_internal(row, column, value, timestamp = nil, mykey = nil, myvalue = nil) p = org.apache.hadoop.hbase.client.Put.new(row.to_s.to_java_bytes) family, qualifier = parse_column_name(column) if timestamp @@ -135,9 +135,19 @@ EOF else p.add(family, qualifier, value.to_s.to_java_bytes) end + if mykey + if myvalue.nil? + raise(ArgumentError, "value should be present if key is not null") + end + set_operation_attributes(p, mykey, myvalue) + end @table.put(p) end + # Apply user metadata to table/column descriptor + def set_operation_attributes(put, mykey, myvalue) + put.setAttribute(mykey, myvalue.to_java_bytes) + end #---------------------------------------------------------------------------------------------- # Delete a cell def _delete_internal(row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) diff --git hbase-shell/src/main/ruby/shell/commands/put.rb hbase-shell/src/main/ruby/shell/commands/put.rb index 17e7a5f..1626bfc 100644 --- hbase-shell/src/main/ruby/shell/commands/put.rb +++ hbase-shell/src/main/ruby/shell/commands/put.rb @@ -26,22 +26,22 @@ Put a cell 'value' at specified table/row/column and optionally timestamp coordinates. To put a cell value into table 't1' at row 'r1' under column 'c1' marked with the time 'ts1', do: - hbase> put 't1', 'r1', 'c1', 'value', ts1 + hbase> put 't1', 'r1', 'c1', 'value', ts1, 'mykey','myvalue' 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 + hbase> t.put 'r1', 'c1', 'value', ts1, 'mykey','myvalue' EOF end - def command(table, row, column, value, timestamp = nil) - put table(table), row, column, value, timestamp + def command(table, row, column, value, timestamp = nil, mykey = nil, myvalue = nil) + put table(table), row, column, value, timestamp, mykey, myvalue end - def put(table, row, column, value, timestamp = nil) + def put(table, row, column, value, timestamp = nil, mykey = nil, myvalue = nil) format_simple_command do - table._put_internal(row, column, value, timestamp) + table._put_internal(row, column, value, timestamp, mykey, myvalue) end end end