HBASE-18142 Deletion of a cell deletes the previous versions too
Signed-off-by: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
5264f04b6d
commit
ff0c1d2fa3
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue