hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chia7...@apache.org
Subject hbase git commit: HBASE-18142 Deletion of a cell deletes the previous versions too
Date Mon, 18 Sep 2017 16:31:13 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 5264f04b6 -> ff0c1d2fa


HBASE-18142 Deletion of a cell deletes the previous versions too

Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>


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

Branch: refs/heads/master
Commit: ff0c1d2fa3addf92ed36139bfc6e21024049cb4f
Parents: 5264f04
Author: Chun-Hao Tang <tang7526@gmail.com>
Authored: Fri Sep 15 02:13:12 2017 +0800
Committer: Chia-Ping Tsai <chia7712@gmail.com>
Committed: Tue Sep 19 00:22:59 2017 +0800

----------------------------------------------------------------------
 hbase-shell/src/main/ruby/hbase/table.rb        | 30 ++++++++-----
 .../src/main/ruby/shell/commands/delete.rb      |  6 +--
 .../src/main/ruby/shell/commands/deleteall.rb   |  2 +-
 hbase-shell/src/test/ruby/hbase/table_test.rb   | 47 ++++++++------------
 4 files changed, 40 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/ff0c1d2f/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 b297f58..7eaf1b3 100644
--- a/hbase-shell/src/main/ruby/hbase/table.rb
+++ b/hbase-shell/src/main/ruby/hbase/table.rb
@@ -24,7 +24,6 @@ include Java
 module Hbase
   class Table
     include HBaseConstants
-
     @@thread_pool = nil
 
     # Add the command 'name' to table s.t. the shell command also called via 'name'
@@ -102,7 +101,7 @@ flush and drop just by typing:
 Note that after dropping a table, your reference to it becomes useless and further usage
 is undefined (and not recommended).
 EOF
-      end
+    end
 
     #---------------------------------------------------------------------------------------------
 
@@ -162,7 +161,8 @@ EOF
     #----------------------------------------------------------------------------------------------
     # Create a Delete mutation
     def _createdelete_internal(row, column = nil,
-                               timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
args = {})
+                               timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
+                               args = {}, all_version = true)
       temptimestamp = timestamp
       if temptimestamp.is_a?(Hash)
         timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP
@@ -179,9 +179,12 @@ EOF
         visibility = args[VISIBILITY]
         set_cell_visibility(d, visibility) if visibility
       end
-      if column
+      if column && all_version
         family, qualifier = parse_column_name(column)
         d.addColumns(family, qualifier, timestamp)
+      elsif column && !all_version
+        family, qualifier = parse_column_name(column)
+        d.addColumn(family, qualifier, timestamp)
       end
       d
     end
@@ -189,7 +192,8 @@ EOF
     #----------------------------------------------------------------------------------------------
     # Delete rows using prefix
     def _deleterows_internal(row, column = nil,
-                             timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
args = {})
+                             timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
+                             args = {}, all_version = true)
       cache = row['CACHE'] ? row['CACHE'] : 100
       prefix = row['ROWPREFIXFILTER']
 
@@ -205,7 +209,7 @@ EOF
       while iter.hasNext
         row = iter.next
         key = org.apache.hadoop.hbase.util.Bytes.toStringBinary(row.getRow)
-        d = _createdelete_internal(key, column, timestamp, args)
+        d = _createdelete_internal(key, column, timestamp, args, all_version)
         list.add(d)
         if list.size >= cache
           @table.delete(list)
@@ -218,23 +222,25 @@ EOF
     #----------------------------------------------------------------------------------------------
     # Delete a cell
     def _delete_internal(row, column,
-                         timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
args = {})
-      _deleteall_internal(row, column, timestamp, args)
+                         timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
+                         args = {}, all_version = false)
+      _deleteall_internal(row, column, timestamp, args, all_version)
     end
 
     #----------------------------------------------------------------------------------------------
     # Delete a row
     def _deleteall_internal(row, column = nil,
-                            timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
args = {})
+                            timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP,
+                            args = {}, all_version = true)
       # delete operation doesn't need read permission. Retaining the read check for
       # meta table as a part of HBASE-5837.
       if is_meta_table?
         raise ArgumentError, 'Row Not Found' if _get_internal(row).nil?
       end
       if row.is_a?(Hash)
-        _deleterows_internal(row, column, timestamp, args)
+        _deleterows_internal(row, column, timestamp, args, all_version)
       else
-        d = _createdelete_internal(row, column, timestamp, args)
+        d = _createdelete_internal(row, column, timestamp, args, all_version)
         @table.delete(d)
       end
     end
@@ -510,7 +516,7 @@ EOF
                  org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes, stoprow.to_java_bytes)
                else
                  org.apache.hadoop.hbase.client.Scan.new(startrow.to_java_bytes)
-        end
+               end
 
         # This will overwrite any startrow/stoprow settings
         scan.setRowPrefixFilter(rowprefixfilter.to_java_bytes) if rowprefixfilter

http://git-wip-us.apache.org/repos/asf/hbase/blob/ff0c1d2f/hbase-shell/src/main/ruby/shell/commands/delete.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/delete.rb b/hbase-shell/src/main/ruby/shell/commands/delete.rb
index 3e4447c..6995959 100644
--- a/hbase-shell/src/main/ruby/shell/commands/delete.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/delete.rb
@@ -40,15 +40,15 @@ t to table 't1', the corresponding command would be:
 EOF
       end
 
-      def command(table, row, column,
+      def command(table, row, column = nil,
                   timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args
= {})
         delete(table(table), row, column, timestamp, args)
       end
 
-      def delete(table, row, column,
+      def delete(table, row, column = nil,
                  timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args =
{})
         @start_time = Time.now
-        table._delete_internal(row, column, timestamp, args)
+        table._delete_internal(row, column, timestamp, args, false)
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/ff0c1d2f/hbase-shell/src/main/ruby/shell/commands/deleteall.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb
index f5444ae..f18fa05 100644
--- a/hbase-shell/src/main/ruby/shell/commands/deleteall.rb
+++ b/hbase-shell/src/main/ruby/shell/commands/deleteall.rb
@@ -58,7 +58,7 @@ EOF
       def deleteall(table, row, column = nil,
                     timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args
= {})
         @start_time = Time.now
-        table._deleteall_internal(row, column, timestamp, args)
+        table._deleteall_internal(row, column, timestamp, args, true)
       end
     end
   end

http://git-wip-us.apache.org/repos/asf/hbase/blob/ff0c1d2f/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 a01514c..81d0a9a 100644
--- a/hbase-shell/src/test/ruby/hbase/table_test.rb
+++ b/hbase-shell/src/test/ruby/hbase/table_test.rb
@@ -106,18 +106,12 @@ module Hbase
       @test_table = table(@test_name)
       
       # Insert data to perform delete operations
-      @test_table.put("101", "x:a", "1")
-      @test_table.put("101", "x:a", "2", Time.now.to_i)
-      
-      @test_table.put("102", "x:a", "1", 1212)
-      @test_table.put("102", "x:a", "2", 1213)
-      
-      @test_table.put(103, "x:a", "3")
-      @test_table.put(103, "x:a", "4")
-      
+      @test_table.put("102", "x:a", "2", 1212)
+      @test_table.put(103, "x:a", "3", 1214)
+
       @test_table.put("104", "x:a", 5)
       @test_table.put("104", "x:b", 6)
-      
+
       @test_table.put(105, "x:a", "3")
       @test_table.put(105, "x:a", "4")
 
@@ -152,21 +146,16 @@ module Hbase
     end
 
     #-------------------------------------------------------------------------------
-
-    define_test "delete should work without timestamp" do
-      @test_table.delete("101", "x:a")
-      res = @test_table._get_internal('101', 'x:a')
-      assert_nil(res)
-    end
-
-    define_test "delete should work with timestamp" do
-      @test_table.delete("102", "x:a", 1214)
+    define_test "delete should work with string keys" do
+      @test_table.delete('102', 'x:a', 1212)
       res = @test_table._get_internal('102', 'x:a')
       assert_nil(res)
     end
 
     define_test "delete should work with integer keys" do
-      @test_table.delete(103, "x:a")
+      res = @test_table._get_internal('103', 'x:a')
+      assert_not_nil(res)
+      @test_table.delete(103, 'x:a', 1214)
       res = @test_table._get_internal('103', 'x:a')
       assert_nil(res)
     end
@@ -266,7 +255,7 @@ module Hbase
         count = @test_table.count COLUMNS => [ 'x:c']
         assert(count == 1)
       ensure
-        @test_table.delete(4, "x:c")
+        @test_table.deleteall(4, 'x:c')
       end
     end
 
@@ -413,8 +402,8 @@ module Hbase
           assert_not_nil(/value=98/.match(res['x:d']))
         ensure
           # clean up newly added columns for this test only.
-          @test_table.delete(1, "x:c")
-          @test_table.delete(1, "x:d")
+          @test_table.deleteall(1, 'x:c')
+          @test_table.deleteall(1, 'x:d')
         end
     end
 
@@ -430,7 +419,7 @@ module Hbase
         assert_nil(res)
       ensure
         # clean up newly added columns for this test only.
-        @test_table.delete(1, "x:v")
+        @test_table.deleteall(1, 'x:v')
       end
     end
 
@@ -613,8 +602,8 @@ module Hbase
         assert_not_nil(/value=98/.match(res['1']['x:d']))
       ensure
         # clean up newly added columns for this test only.
-        @test_table.delete(1, "x:c")
-        @test_table.delete(1, "x:d")
+        @test_table.deleteall(1, 'x:c')
+        @test_table.deleteall(1, 'x:d')
       end
     end
 
@@ -632,7 +621,7 @@ module Hbase
         assert_equal(res, {}, "Result is not empty")
       ensure
         # clean up newly added columns for this test only.
-        @test_table.delete(1, "x:v")
+        @test_table.deleteall(1, 'x:v')
       end
     end
 
@@ -648,7 +637,7 @@ module Hbase
         assert_nil(res['2'])
       ensure
         # clean up newly added columns for this test only.
-        @test_table.delete(4, "x:a")
+        @test_table.deleteall(4, 'x:a')
       end
     end
 
@@ -666,7 +655,7 @@ module Hbase
         res = @test_table._get_internal('ttlTest', 'x:a')
         assert_nil(res)
       ensure
-        @test_table.delete('ttlTest', 'x:a')
+        @test_table.deleteall('ttlTest', 'x:a')
       end
     end
 


Mime
View raw message