hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject hbase git commit: HBASE-21178 [BC break] : Get and Scan operation with a custom converter_class not working
Date Fri, 12 Oct 2018 15:29:08 GMT
Repository: hbase
Updated Branches:
  refs/heads/master fa5fa6ecd -> 05f8bea62


HBASE-21178 [BC break] : Get and Scan operation with a custom converter_class not working

Signed-off-by: tedyu <yuzhihong@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/05f8bea6
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/05f8bea6
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/05f8bea6

Branch: refs/heads/master
Commit: 05f8bea6202efcbb0b75cbd04d89dccba373c3ef
Parents: fa5fa6e
Author: subrat.mishra <subrat.mishra@yahoo.com>
Authored: Tue Sep 18 11:03:53 2018 +0530
Committer: tedyu <yuzhihong@gmail.com>
Committed: Fri Oct 12 08:28:58 2018 -0700

----------------------------------------------------------------------
 hbase-shell/src/main/ruby/hbase/table.rb      |  9 ++++---
 hbase-shell/src/test/ruby/hbase/table_test.rb | 30 ++++++++++++++++++++++
 2 files changed, 36 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/05f8bea6/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 55211b0..7a334a0 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -778,13 +778,16 @@ EOF
     end
 
     def convert_bytes(bytes, converter_class = nil, converter_method = nil)
-      convert_bytes_with_position(bytes, 0, bytes.length, converter_class, converter_method)
+      # Avoid nil
+      converter_class ||= 'org.apache.hadoop.hbase.util.Bytes'
+      converter_method ||= 'toStringBinary'
+      eval(converter_class).method(converter_method).call(bytes)
     end
 
     def convert_bytes_with_position(bytes, offset, len, converter_class, converter_method)
       # Avoid nil
-      converter_class = 'org.apache.hadoop.hbase.util.Bytes' unless converter_class
-      converter_method = 'toStringBinary' unless converter_method
+      converter_class ||= 'org.apache.hadoop.hbase.util.Bytes'
+      converter_method ||= 'toStringBinary'
       eval(converter_class).method(converter_method).call(bytes, offset, len)
     end
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/05f8bea6/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 9b15f83..5ec317a 100644
--- a/hbase-shell/src/test/ruby/hbase/table_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/table_test.rb
@@ -437,6 +437,21 @@ module Hbase
       end
     end
 
+    define_test 'get should work with a custom converter class' do
+      @test_table.put(1, 'x:v', 1234)
+      begin
+        res = @test_table._get_internal('1', 'COLUMNS' =>
+                    ['x:v:c(org.apache.hadoop.hbase.util.Bytes).len'])
+        assert_not_nil(res)
+        assert_kind_of(Hash, res)
+        assert_not_nil(res['x:v'])
+        assert_not_nil(/value=4/.match(res['x:v']))
+      ensure
+        # clean up newly added columns for this test only.
+        @test_table.deleteall(1, 'x:v')
+      end
+    end
+
     #-------------------------------------------------------------------------------
 
     define_test "scan should work w/o any params" do
@@ -679,6 +694,21 @@ module Hbase
       assert_not_nil(res)
     end
 
+    define_test 'scan should work with a custom converter class' do
+      @test_table.put(1, 'x:v', 1234)
+      begin
+        res = @test_table._scan_internal 'COLUMNS' =>
+                    ['x:v:c(org.apache.hadoop.hbase.util.Bytes).len']
+        assert_not_nil(res)
+        assert_kind_of(Hash, res)
+        assert_not_nil(res['1']['x:v'])
+        assert_not_nil(/value=4/.match(res['1']['x:v']))
+      ensure
+        # clean up newly added columns for this test only.
+        @test_table.deleteall(1, 'x:v')
+      end
+    end
+
     define_test "mutation with TTL should expire" do
       @test_table.put('ttlTest', 'x:a', 'foo', { TTL => 1000 } )
       begin


Mime
View raw message