From ecfe54a1bf996c162a61c0e3b7070033f32964c9 Mon Sep 17 00:00:00 2001 From: "jeongmin.kim" Date: Mon, 28 Mar 2022 19:52:42 +0900 Subject: [PATCH] HBASE-26895 on hbase shell, 'delete/deleteall' for a columnfamily is not working --- hbase-shell/src/main/ruby/hbase/table.rb | 12 ++++++++++-- hbase-shell/src/test/ruby/hbase/table_test.rb | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index dae1e106f507..5192c63aa6d3 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -189,10 +189,18 @@ def _createdelete_internal(row, column = nil, if column != "" if column && all_version family, qualifier = parse_column_name(column) - d.addColumns(family, qualifier, timestamp) + if qualifier + d.addColumns(family, qualifier, timestamp) + else + d.addFamily(family, timestamp) + end elsif column && !all_version family, qualifier = parse_column_name(column) - d.addColumn(family, qualifier, timestamp) + if qualifier + d.addColumn(family, qualifier, timestamp) + else + d.addFamilyVersion(family, timestamp) + end end end d diff --git a/hbase-shell/src/test/ruby/hbase/table_test.rb b/hbase-shell/src/test/ruby/hbase/table_test.rb index cb274f814aa9..05b80725efc8 100644 --- a/hbase-shell/src/test/ruby/hbase/table_test.rb +++ b/hbase-shell/src/test/ruby/hbase/table_test.rb @@ -164,6 +164,21 @@ def teardown assert_nil(res) end + define_test "delete should set proper cell type" do + del = @test_table._createdelete_internal('104', 'x:a', 1212) + assert_equal(del.get('x'.to_java_bytes, 'a'.to_java_bytes).get(0).getType.getCode, + org.apache.hadoop.hbase::KeyValue::Type::DeleteColumn.getCode) + del = @test_table._createdelete_internal('104', 'x:a', 1212, [], false) + assert_equal(del.get('x'.to_java_bytes, 'a'.to_java_bytes).get(0).getType.getCode, + org.apache.hadoop.hbase::KeyValue::Type::Delete.getCode) + del = @test_table._createdelete_internal('104', 'x', 1212) + assert_equal(del.get('x'.to_java_bytes, nil).get(0).getType.getCode, + org.apache.hadoop.hbase::KeyValue::Type::DeleteFamily.getCode) + del = @test_table._createdelete_internal('104', 'x', 1212, [], false) + assert_equal(del.get('x'.to_java_bytes, nil).get(0).getType.getCode, + org.apache.hadoop.hbase::KeyValue::Type::DeleteFamilyVersion.getCode) + end + #------------------------------------------------------------------------------- define_test "deleteall should work w/o columns and timestamps" do