HBASE-12268 Add support for Scan.setRowPrefixFilter to shell (Niels Basjes)

This commit is contained in:
tedyu 2015-01-06 11:17:52 -08:00
parent 141b33a630
commit 06b386f254
5 changed files with 32 additions and 7 deletions

View File

@ -42,6 +42,7 @@ module HBaseConstants
METADATA = org.apache.hadoop.hbase.HConstants::METADATA METADATA = org.apache.hadoop.hbase.HConstants::METADATA
STOPROW = "STOPROW" STOPROW = "STOPROW"
STARTROW = "STARTROW" STARTROW = "STARTROW"
ROWPREFIXFILTER = "ROWPREFIXFILTER"
ENDROW = STOPROW ENDROW = STOPROW
RAW = "RAW" RAW = "RAW"
LIMIT = "LIMIT" LIMIT = "LIMIT"

View File

@ -411,6 +411,7 @@ EOF
filter = args["FILTER"] filter = args["FILTER"]
startrow = args["STARTROW"] || '' startrow = args["STARTROW"] || ''
stoprow = args["STOPROW"] stoprow = args["STOPROW"]
rowprefixfilter = args["ROWPREFIXFILTER"]
timestamp = args["TIMESTAMP"] timestamp = args["TIMESTAMP"]
columns = args["COLUMNS"] || args["COLUMN"] || [] columns = args["COLUMNS"] || args["COLUMN"] || []
# If CACHE_BLOCKS not set, then default 'true'. # If CACHE_BLOCKS not set, then default 'true'.
@ -435,6 +436,9 @@ EOF
org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes) org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes)
end end
# This will overwrite any startrow/stoprow settings
scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter
columns.each do |c| columns.each do |c|
family, qualifier = parse_column_name(c.to_s) family, qualifier = parse_column_name(c.to_s)
if qualifier if qualifier

View File

@ -24,8 +24,8 @@ module Shell
return <<-EOF return <<-EOF
Scan a table; pass table name and optionally a dictionary of scanner Scan a table; pass table name and optionally a dictionary of scanner
specifications. Scanner specifications may include one or more of: specifications. Scanner specifications may include one or more of:
TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, TIMESTAMP, MAXLENGTH, TIMERANGE, FILTER, LIMIT, STARTROW, STOPROW, ROWPREFIXFILTER, TIMESTAMP,
or COLUMNS, CACHE MAXLENGTH or COLUMNS, CACHE
If no columns are specified, all columns will be scanned. If no columns are specified, all columns will be scanned.
To scan all members of a column family, leave the qualifier empty as in 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', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]} hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
hbase> scan 't1', {REVERSED => true} hbase> scan 't1', {REVERSED => true}
hbase> scan 't1', {FILTER => "(PrefixFilter ('row2') AND hbase> scan 't1', {ROWPREFIXFILTER => 'row2', FILTER => "
(QualifierFilter (>=, 'binary:xyz'))) AND (TimestampsFilter ( 123, 456))"} (QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"}
hbase> scan 't1', {FILTER => hbase> scan 't1', {FILTER =>
org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)} org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}
hbase> scan 't1', {CONSISTENCY => 'TIMELINE'} hbase> scan 't1', {CONSISTENCY => 'TIMELINE'}

View File

@ -24,7 +24,7 @@ Set the visibility expression on one or more existing cells.
Pass table name, visibility expression, and a dictionary containing Pass table name, visibility expression, and a dictionary containing
scanner specifications. Scanner specifications may include one or more 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. If no columns are specified, all columns will be included.
To include all members of a column family, leave the qualifier empty as in 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', {COLUMNS => ['c1', 'c2']}
hbase> set_visibility 't1', '(A&B)|C', {COLUMNS => 'c1', hbase> set_visibility 't1', '(A&B)|C', {COLUMNS => 'c1',
TIMERANGE => [1303668804, 1303668904]} TIMERANGE => [1303668804, 1303668904]}
hbase> set_visibility 't1', 'A&B&C', {FILTER => "(PrefixFilter ('row2') AND hbase> set_visibility 't1', 'A&B&C', {ROWPREFIXFILTER => 'row2',
(QualifierFilter (>=, 'binary:xyz'))) AND FILTER => "(QualifierFilter (>=, 'binary:xyz')) AND
(TimestampsFilter ( 123, 456))"} (TimestampsFilter ( 123, 456))"}
This command will only affect existing cells and is expected to be mainly This command will only affect existing cells and is expected to be mainly

View File

@ -412,6 +412,26 @@ module Hbase
assert_nil(res['2']) assert_nil(res['2'])
end 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 define_test "scan should support LIMIT parameter" do
res = @test_table._scan_internal LIMIT => 1 res = @test_table._scan_internal LIMIT => 1
assert_not_nil(res) assert_not_nil(res)