You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by la...@apache.org on 2012/11/05 06:26:52 UTC

svn commit: r1405697 - in /hbase/branches/0.94/src: main/ruby/hbase/table.rb main/ruby/shell/commands/get.rb test/ruby/hbase/table_test.rb

Author: larsh
Date: Mon Nov  5 05:26:52 2012
New Revision: 1405697

URL: http://svn.apache.org/viewvc?rev=1405697&view=rev
Log:
HBASE-7089 Allow filter to be specified for Get from HBase shell (Aditya Kishore)

Modified:
    hbase/branches/0.94/src/main/ruby/hbase/table.rb
    hbase/branches/0.94/src/main/ruby/shell/commands/get.rb
    hbase/branches/0.94/src/test/ruby/hbase/table_test.rb

Modified: hbase/branches/0.94/src/main/ruby/hbase/table.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/ruby/hbase/table.rb?rev=1405697&r1=1405696&r2=1405697&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/ruby/hbase/table.rb (original)
+++ hbase/branches/0.94/src/main/ruby/hbase/table.rb Mon Nov  5 05:26:52 2012
@@ -118,6 +118,7 @@ module Hbase
 
       # 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]
@@ -162,6 +163,12 @@ module Hbase
         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

Modified: hbase/branches/0.94/src/main/ruby/shell/commands/get.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/ruby/shell/commands/get.rb?rev=1405697&r1=1405696&r2=1405697&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/ruby/shell/commands/get.rb (original)
+++ hbase/branches/0.94/src/main/ruby/shell/commands/get.rb Mon Nov  5 05:26:52 2012
@@ -33,6 +33,7 @@ a dictionary of column(s), timestamp, ti
   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']

Modified: hbase/branches/0.94/src/test/ruby/hbase/table_test.rb
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/ruby/hbase/table_test.rb?rev=1405697&r1=1405696&r2=1405697&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/ruby/hbase/table_test.rb (original)
+++ hbase/branches/0.94/src/test/ruby/hbase/table_test.rb Mon Nov  5 05:26:52 2012
@@ -313,6 +313,22 @@ module Hbase
       assert_equal(res.keys.sort, [ 'x:a', 'x:b' ])
     end
 
+    define_test "get should support FILTER" do
+      @test_table.put(1, "x:v", "thisvalue")
+      begin
+        res = @test_table.get('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('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
@@ -418,5 +434,24 @@ module Hbase
       res = @test_table.scan { |row, cells| rows[row] = cells }
       assert_equal(rows.keys.size, res)
     end
+
+    define_test "scan should support FILTER" do
+      @test_table.put(1, "x:v", "thisvalue")
+      begin
+        res = @test_table.scan 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 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