hbase-shell/src/main/ruby/hbase/table.rb | 55 ++++++++++++++++++++-- hbase-shell/src/main/ruby/shell/commands/delete.rb | 9 ++-- .../src/main/ruby/shell/commands/deleteall.rb | 12 ++--- hbase-shell/src/main/ruby/shell/commands/put.rb | 2 +- 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 1984177..4f519de 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -160,18 +160,63 @@ EOF #---------------------------------------------------------------------------------------------- # Delete a cell - def _delete_internal(row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) - _deleteall_internal(row, column, timestamp) + def _delete_internal(row, column, timestamp = nil, args={}) + raise ArgumentError, "Row Not Found" if _get_internal(row).nil? + ts = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP + d = org.apache.hadoop.hbase.client.Delete.new(row.to_s.to_java_bytes, ts) + #Case where attributes are specified without timestamp + if timestamp.kind_of?(Hash) + timestamp.each do |k, v| + if v.kind_of?(String) + set_cell_visibility(d, v) if v + end + end + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP + end + if args.any? + visibility = args[VISIBILITY] + set_cell_visibility(d, visibility) if visibility + end + family, qualifier = parse_column_name(column) + d.deleteColumn(family, qualifier, timestamp) + @table.delete(d) end #---------------------------------------------------------------------------------------------- # Delete a row - def _deleteall_internal(row, column = nil, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) + def _deleteall_internal(row, column = nil, timestamp = nil, args={}) raise ArgumentError, "Row Not Found" if _get_internal(row).nil? - d = org.apache.hadoop.hbase.client.Delete.new(row.to_s.to_java_bytes, timestamp) + ts = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP + d = org.apache.hadoop.hbase.client.Delete.new(row.to_s.to_java_bytes, ts) + if args.any? + visibility = args[VISIBILITY] + set_cell_visibility(d, visibility) if visibility + end + #Case where attributes are specified without column + if column.kind_of?(Hash) + column.each do |k, v| + if v.kind_of?(String) + set_cell_visibility(d, v) if v + end + end + column = nil + end + #Case where attributes are specified without timestamp + if timestamp.kind_of?(Hash) + timestamp.each do |k, v| + if v.kind_of?(String) + set_cell_visibility(d, v) if v + end + end + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP + end if column family, qualifier = parse_column_name(column) - d.deleteColumns(family, qualifier, timestamp) + if qualifier.nil? + d.deleteFamily(family, timestamp) + else + d.deleteColumns(family, qualifier, timestamp) + end end @table.delete(d) end diff --git a/hbase-shell/src/main/ruby/shell/commands/delete.rb b/hbase-shell/src/main/ruby/shell/commands/delete.rb index a0c50e3..b1725eb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb @@ -30,6 +30,7 @@ marked with the time 'ts1', do: hbase> delete 'ns1:t1', 'r1', 'c1', ts1 hbase> delete 't1', 'r1', 'c1', ts1 + hbase>delete 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'} The same command can also be run on a table reference. Suppose you had a reference t to table 't1', the corresponding command would be: @@ -38,13 +39,13 @@ t to table 't1', the corresponding command would be: EOF end - def command(table, row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) - delete(table(table), row, column, timestamp) + def command(table, row, column, timestamp = nil, args = {}) + delete(table(table), row, column, timestamp, args) end - def delete(table, row, column, timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) + def delete(table, row, column, timestamp = nil, args = {}) format_simple_command do - table._delete_internal(row, column, timestamp) + table._delete_internal(row, column, timestamp, args) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb index 197dbd4..fccea2f 100644 --- a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb +++ b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb @@ -28,26 +28,26 @@ a column and timestamp. Examples: hbase> deleteall 'ns1:t1', 'r1' hbase> deleteall 't1', 'r1' hbase> deleteall 't1', 'r1', 'c1' - hbase> deleteall 't1', 'r1', 'c1', ts1 + hbase> deleteall 't1', 'r1', 'c1', 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.deleteall 'r1' hbase> t.deleteall 'r1', 'c1' - hbase> t.deleteall 'r1', 'c1', ts1 + hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'} EOF end def command(table, row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) - deleteall(table(table), row, column, timestamp) + timestamp = nil, args={}) + deleteall(table(table), row, column, timestamp, args) end def deleteall(table, row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) + timestamp = nil, args={}) format_simple_command do - table._deleteall_internal(row, column, timestamp) + table._deleteall_internal(row, column, timestamp, args) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/put.rb b/hbase-shell/src/main/ruby/shell/commands/put.rb index 4879200..2b47a4d 100644 --- a/hbase-shell/src/main/ruby/shell/commands/put.rb +++ b/hbase-shell/src/main/ruby/shell/commands/put.rb @@ -31,7 +31,7 @@ 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', {ATTRIBUTES=>{'mykey'=>'myvalue'}} hbase> put 't1', 'r1', 'c1', 'value', ts1, {ATTRIBUTES=>{'mykey'=>'myvalue'}} - hbase> put 't1', 'r1', 'c1', 'value', ts1, {VISIBILITY=>'PRIVATE|SECRET'}} + 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: