HBASE-20327 When qualifier is not specified, append and incr operation do not work (shell)

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
Nihal Jain 2018-04-19 02:36:33 +05:30 committed by Chia-Ping Tsai
parent 31e3ef6792
commit ce08826f0d
2 changed files with 14 additions and 6 deletions

View File

@ -251,14 +251,12 @@ EOF
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Increment a counter atomically # Increment a counter atomically
# rubocop:disable Metrics/AbcSize, CyclomaticComplexity, MethodLength
def _incr_internal(row, column, value = nil, args = {}) def _incr_internal(row, column, value = nil, args = {})
value = 1 if value.is_a?(Hash) value = 1 if value.is_a?(Hash)
value ||= 1 value ||= 1
incr = org.apache.hadoop.hbase.client.Increment.new(row.to_s.to_java_bytes) incr = org.apache.hadoop.hbase.client.Increment.new(row.to_s.to_java_bytes)
family, qualifier = parse_column_name(column) family, qualifier = parse_column_name(column)
if qualifier.nil?
raise ArgumentError, 'Failed to provide both column family and column qualifier for incr'
end
if args.any? if args.any?
attributes = args[ATTRIBUTES] attributes = args[ATTRIBUTES]
visibility = args[VISIBILITY] visibility = args[VISIBILITY]
@ -282,9 +280,6 @@ EOF
def _append_internal(row, column, value, args = {}) def _append_internal(row, column, value, args = {})
append = org.apache.hadoop.hbase.client.Append.new(row.to_s.to_java_bytes) append = org.apache.hadoop.hbase.client.Append.new(row.to_s.to_java_bytes)
family, qualifier = parse_column_name(column) family, qualifier = parse_column_name(column)
if qualifier.nil?
raise ArgumentError, 'Failed to provide both column family and column qualifier for append'
end
if args.any? if args.any?
attributes = args[ATTRIBUTES] attributes = args[ATTRIBUTES]
visibility = args[VISIBILITY] visibility = args[VISIBILITY]
@ -302,6 +297,7 @@ EOF
org.apache.hadoop.hbase.util.Bytes.toStringBinary(cell.getValueArray, org.apache.hadoop.hbase.util.Bytes.toStringBinary(cell.getValueArray,
cell.getValueOffset, cell.getValueLength) cell.getValueOffset, cell.getValueLength)
end end
# rubocop:enable Metrics/AbcSize, CyclomaticComplexity, MethodLength
#---------------------------------------------------------------------------------------------- #----------------------------------------------------------------------------------------------
# Count rows in a table # Count rows in a table

View File

@ -186,7 +186,19 @@ module Hbase
@test_table.append("123", 'x:cnt2', '123') @test_table.append("123", 'x:cnt2', '123')
assert_equal("123123", @test_table._append_internal("123", 'x:cnt2', '123')) assert_equal("123123", @test_table._append_internal("123", 'x:cnt2', '123'))
end end
define_test 'append should work without qualifier' do
@test_table.append('1001', 'x', '123')
assert_equal('123321', @test_table._append_internal('1001', 'x', '321'))
end
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
define_test 'incr should work without qualifier' do
@test_table.incr('1010', 'x', 123)
assert_equal(123, @test_table._get_counter_internal('1010', 'x'))
@test_table.incr('1010', 'x', 123)
assert_equal(246, @test_table._get_counter_internal('1010', 'x'))
end
define_test "get_counter should work with integer keys" do define_test "get_counter should work with integer keys" do
@test_table.incr(12345, 'x:cnt') @test_table.incr(12345, 'x:cnt')