HBASE-7089 Allow filter to be specified for Get from HBase shell

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1405640 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2012-11-04 21:09:02 +00:00
parent 73911b1740
commit 867ff9fc69
3 changed files with 45 additions and 2 deletions

View File

@ -210,6 +210,7 @@ EOF
# Get maxlength parameter if passed
maxlength = args.delete(MAXLENGTH) if args[MAXLENGTH]
filter = args.delete(FILTER) if args[FILTER]
unless args.empty?
columns = args[COLUMN] || args[COLUMNS]
@ -254,6 +255,12 @@ EOF
end
end
unless filter.class == String
get.setFilter(filter)
else
get.setFilter(org.apache.hadoop.hbase.filter.ParseFilter.new.parseFilterString(filter))
end
# Call hbase for the results
result = @table.get(get)
return nil if result.isEmpty

View File

@ -32,6 +32,7 @@ a dictionary of column(s), timestamp, timerange and versions. Examples:
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> get 't1', 'r1', 'c1'
hbase> get 't1', 'r1', 'c1', 'c2'
hbase> get 't1', 'r1', ['c1', 'c2']
@ -61,6 +62,7 @@ would be:
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']

View File

@ -328,6 +328,22 @@ module Hbase
end
end
define_test "get should support FILTER" do
@test_table.put(1, "x:v", "thisvalue")
begin
res = @test_table._get_internal('1', FILTER => "ValueFilter(=, 'binary:thisvalue')")
assert_not_nil(res)
assert_kind_of(Hash, res)
assert_not_nil(res['x:v'])
assert_nil(res['x:a'])
res = @test_table._get_internal('1', FILTER => "ValueFilter(=, 'binary:thatvalue')")
assert_nil(res)
ensure
# clean up newly added columns for this test only.
@test_table.delete(1, "x:v")
end
end
#-------------------------------------------------------------------------------
define_test "scan should work w/o any params" do
@ -447,8 +463,26 @@ module Hbase
# clean up newly added columns for this test only.
@test_table.delete(1, "x:c")
@test_table.delete(1, "x:d")
end
end
end
define_test "scan should support FILTER" do
@test_table.put(1, "x:v", "thisvalue")
begin
res = @test_table._scan_internal FILTER => "ValueFilter(=, 'binary:thisvalue')"
assert_not_equal(res, {}, "Result is empty")
assert_kind_of(Hash, res)
assert_not_nil(res['1'])
assert_not_nil(res['1']['x:v'])
assert_nil(res['1']['x:a'])
assert_nil(res['2'])
res = @test_table._scan_internal FILTER => "ValueFilter(=, 'binary:thatvalue')"
assert_equal(res, {}, "Result is not empty")
ensure
# clean up newly added columns for this test only.
@test_table.delete(1, "x:v")
end
end
end
end