From 0acab9caba70d39a3aedaccfb63d95c697462ce6 Mon Sep 17 00:00:00 2001 From: Ramkrishna Date: Wed, 9 Jul 2014 11:50:24 +0530 Subject: [PATCH] HBASE-11088 Support Visibility Expression Deletes in Shell (Ram) --- hbase-shell/src/main/ruby/hbase/table.rb | 23 ++++++++++++++++--- .../src/main/ruby/shell/commands/delete.rb | 12 ++++++---- .../src/main/ruby/shell/commands/deleteall.rb | 10 ++++---- .../src/main/ruby/shell/commands/put.rb | 2 +- 4 files changed, 35 insertions(+), 12 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 5f710708cca..14fe1e4e41b 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -160,15 +160,32 @@ 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 = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + _deleteall_internal(row, column, timestamp, args) 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 = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) raise ArgumentError, "Row Not Found" if _get_internal(row).nil? + temptimestamp = timestamp + if temptimestamp.kind_of?(Hash) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP + end d = org.apache.hadoop.hbase.client.Delete.new(row.to_s.to_java_bytes, timestamp) + if temptimestamp.kind_of?(Hash) + temptimestamp.each do |k, v| + if v.kind_of?(String) + set_cell_visibility(d, v) if v + end + end + end + if args.any? + visibility = args[VISIBILITY] + set_cell_visibility(d, visibility) if visibility + end if column family, qualifier = parse_column_name(column) d.deleteColumns(family, qualifier, timestamp) diff --git a/hbase-shell/src/main/ruby/shell/commands/delete.rb b/hbase-shell/src/main/ruby/shell/commands/delete.rb index a0c50e30adc..dcb83414f62 100644 --- a/hbase-shell/src/main/ruby/shell/commands/delete.rb +++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb @@ -30,21 +30,25 @@ 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: hbase> t.delete 'r1', 'c1', ts1 + hbase> t.delete 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'} 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 = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, 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 = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, 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 197dbd40df0..e6118c9144b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb +++ b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb @@ -29,6 +29,7 @@ a column and timestamp. Examples: 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: @@ -36,18 +37,19 @@ 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 = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {}) + deleteall(table(table), row, column, timestamp, args) end def deleteall(table, row, column = nil, - timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP) + timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, 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 487920057b0..2b47a4d5c6e 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: