Repository: hbase Updated Branches: refs/heads/branch-1 141b33a63 -> 06b386f25
HBASE-12268 Add support for Scan.setRowPrefixFilter to shell (Niels Basjes) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/06b386f2 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/06b386f2 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/06b386f2 Branch: refs/heads/branch-1 Commit: 06b386f2547b26fe9cd38d12bcb110b7c70b7853 Parents: 141b33a Author: tedyu <[email protected]> Authored: Tue Jan 6 11:17:52 2015 -0800 Committer: tedyu <[email protected]> Committed: Tue Jan 6 11:17:52 2015 -0800 ---------------------------------------------------------------------- hbase-shell/src/main/ruby/hbase.rb | 1 + hbase-shell/src/main/ruby/hbase/table.rb | 4 ++++ .../src/main/ruby/shell/commands/scan.rb | 8 ++++---- .../main/ruby/shell/commands/set_visibility.rb | 6 +++--- hbase-shell/src/test/ruby/hbase/table_test.rb | 20 ++++++++++++++++++++ 5 files changed, 32 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/06b386f2/hbase-shell/src/main/ruby/hbase.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/hbase.rb b/hbase-shell/src/main/ruby/hbase.rb index 121fd53..dd9ed90 100644 --- a/hbase-shell/src/main/ruby/hbase.rb +++ b/hbase-shell/src/main/ruby/hbase.rb @@ -42,6 +42,7 @@ module HBaseConstants METADATA = org.apache.hadoop.hbase.HConstants::METADATA STOPROW = "STOPROW" STARTROW = "STARTROW" + ROWPREFIXFILTER = "ROWPREFIXFILTER" ENDROW = STOPROW RAW = "RAW" LIMIT = "LIMIT" http://git-wip-us.apache.org/repos/asf/hbase/blob/06b386f2/hbase-shell/src/main/ruby/hbase/table.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 83695bd..7258588 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -411,6 +411,7 @@ EOF filter = args["FILTER"] startrow = args["STARTROW"] || '' stoprow = args["STOPROW"] + rowprefixfilter = args["ROWPREFIXFILTER"] timestamp = args["TIMESTAMP"] columns = args["COLUMNS"] || args["COLUMN"] || [] # If CACHE_BLOCKS not set, then default 'true'. @@ -435,6 +436,9 @@ EOF org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) end + # This will overwrite any startrow/stoprow settings + scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter + columns.each do |c| family, qualifier = parse_column_name(c.to_s) if qualifier http://git-wip-us.apache.org/repos/asf/hbase/blob/06b386f2/hbase-shell/src/main/ruby/shell/commands/scan.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/scan.rb b/hbase-shell/src/main/ruby/shell/commands/scan.rb index 8ce8d46..da4dace 100644 --- a/hbase-shell/src/main/ruby/shell/commands/scan.rb +++ b/hbase-shell/src/main/ruby/shell/commands/scan.rb @@ -24,8 +24,8 @@ module Shell return <<-EOF Scan a table; pass table name and optionally a dictionary of scanner specifications. Scanner specifications may include one or more of: -TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH, -or COLUMNS, CACHE +TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, ROWPREFIXFILTER, TIMESTAMP, +MAXLENGTH or COLUMNS, CACHE If no columns are specified, all columns will be scanned. To scan all members of a column family, leave the qualifier empty as in @@ -44,8 +44,8 @@ Some examples: hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'} hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]} hbase> scan 't1', {REVERSED => true} - hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND - (QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"} + hbase> scan 't1', {ROWPREFIXFILTER => 'row2', FILTER => " + (QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"} hbase> scan 't1', {FILTER => org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)} hbase> scan 't1', {CONSISTENCY => 'TIMELINE'} http://git-wip-us.apache.org/repos/asf/hbase/blob/06b386f2/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb b/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb index b2b57b1..59779fb 100644 --- a/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb +++ b/hbase-shell/src/main/ruby/shell/commands/set_visibility.rb @@ -24,7 +24,7 @@ Set the visibility expression on one or more existing cells. Pass table name, visibility expression, and a dictionary containing scanner specifications. Scanner specifications may include one or more -of: TIMERANGE, FILTER, STARTROW, STOPROW, TIMESTAMP, or COLUMNS +of: TIMERANGE, FILTER, STARTROW, STOPROW, ROWPREFIXFILTER, TIMESTAMP, or COLUMNS If no columns are specified, all columns will be included. To include all members of a column family, leave the qualifier empty as in @@ -40,8 +40,8 @@ Examples: hbase> set_visibility 't1', 'A|B', {COLUMNS => ['c1', 'c2']} hbase> set_visibility 't1', '(A&B)|C', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]} - hbase> set_visibility 't1', 'A&B&C', {FILTER => "(PrefixFilter ('row2') AND - (QualifierFilter (>=, 'binary:xyz'))) AND + hbase> set_visibility 't1', 'A&B&C', {ROWPREFIXFILTER => 'row2', + FILTER => "(QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"} This command will only affect existing cells and is expected to be mainly http://git-wip-us.apache.org/repos/asf/hbase/blob/06b386f2/hbase-shell/src/test/ruby/hbase/table_test.rb ---------------------------------------------------------------------- diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index fa2990d..9e4765f 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -412,6 +412,26 @@ module Hbase assert_nil(res['2']) end + define_test "scan should support ROWPREFIXFILTER parameter (test 1)" do + res = @test_table._scan_internal ROWPREFIXFILTER => '1' + assert_not_nil(res) + assert_kind_of(Hash, res) + assert_not_nil(res['1']) + assert_not_nil(res['1']['x:a']) + assert_not_nil(res['1']['x:b']) + assert_nil(res['2']) + end + + define_test "scan should support ROWPREFIXFILTER parameter (test 2)" do + res = @test_table._scan_internal ROWPREFIXFILTER => '2' + assert_not_nil(res) + assert_kind_of(Hash, res) + assert_nil(res['1']) + assert_not_nil(res['2']) + assert_not_nil(res['2']['x:a']) + assert_not_nil(res['2']['x:b']) + end + define_test "scan should support LIMIT parameter" do res = @test_table._scan_internal LIMIT => 1 assert_not_nil(res)
