HBASE-16381 Shell deleteall command should support row key prefixes (Yi Liang)
This commit is contained in:
parent
8ef6c76344
commit
1d6c90b496
@ -160,21 +160,9 @@ EOF
|
|||||||
end
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------
|
||||||
# Delete a cell
|
# Create a Delete mutation
|
||||||
def _delete_internal(row, column,
|
def _createdelete_internal(row, column = nil,
|
||||||
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
|
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
|
||||||
_deleteall_internal(row, column, timestamp, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------
|
|
||||||
# Delete a row
|
|
||||||
def _deleteall_internal(row, column = nil,
|
|
||||||
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
|
|
||||||
# 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
|
|
||||||
temptimestamp = timestamp
|
temptimestamp = timestamp
|
||||||
if temptimestamp.kind_of?(Hash)
|
if temptimestamp.kind_of?(Hash)
|
||||||
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP
|
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP
|
||||||
@ -195,8 +183,61 @@ EOF
|
|||||||
family, qualifier = parse_column_name(column)
|
family, qualifier = parse_column_name(column)
|
||||||
d.addColumns(family, qualifier, timestamp)
|
d.addColumns(family, qualifier, timestamp)
|
||||||
end
|
end
|
||||||
|
return d
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Delete rows using prefix
|
||||||
|
def _deleterows_internal(row, column = nil,
|
||||||
|
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args={})
|
||||||
|
cache = row["CACHE"] ? row["CACHE"] : 100
|
||||||
|
prefix = row["ROWPREFIXFILTER"]
|
||||||
|
|
||||||
|
# create scan to get table names using prefix
|
||||||
|
scan = org.apache.hadoop.hbase.client.Scan.new
|
||||||
|
scan.setRowPrefixFilter(prefix.to_java_bytes)
|
||||||
|
# Run the scanner to get all rowkeys
|
||||||
|
scanner = @table.getScanner(scan)
|
||||||
|
# Create a list to store all deletes
|
||||||
|
list = java.util.ArrayList.new
|
||||||
|
# Iterate results
|
||||||
|
iter = scanner.iterator
|
||||||
|
while iter.hasNext
|
||||||
|
row = iter.next
|
||||||
|
key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow)
|
||||||
|
d = _createdelete_internal(key, column, timestamp, args)
|
||||||
|
list.add(d)
|
||||||
|
if list.size >= cache
|
||||||
|
@table.delete(list)
|
||||||
|
list.clear
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@table.delete(list)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Delete a cell
|
||||||
|
def _delete_internal(row, column,
|
||||||
|
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
|
||||||
|
_deleteall_internal(row, column, timestamp, args)
|
||||||
|
end
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------------------------
|
||||||
|
# Delete a row
|
||||||
|
def _deleteall_internal(row, column = nil,
|
||||||
|
timestamp = org.apache.hadoop.hbase.HConstants::LATEST_TIMESTAMP, args = {})
|
||||||
|
# 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.kind_of?(Hash)
|
||||||
|
_deleterows_internal(row, column, timestamp, args)
|
||||||
|
else
|
||||||
|
d = _createdelete_internal(row, column, timestamp, args)
|
||||||
@table.delete(d)
|
@table.delete(d)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#----------------------------------------------------------------------------------------------
|
#----------------------------------------------------------------------------------------------
|
||||||
# Increment a counter atomically
|
# Increment a counter atomically
|
||||||
|
@ -23,7 +23,8 @@ module Shell
|
|||||||
def help
|
def help
|
||||||
return <<-EOF
|
return <<-EOF
|
||||||
Delete all cells in a given row; pass a table name, row, and optionally
|
Delete all cells in a given row; pass a table name, row, and optionally
|
||||||
a column and timestamp. Examples:
|
a column and timestamp. Deleteall also support deleting a row range using a
|
||||||
|
row key prefix. Examples:
|
||||||
|
|
||||||
hbase> deleteall 'ns1:t1', 'r1'
|
hbase> deleteall 'ns1:t1', 'r1'
|
||||||
hbase> deleteall 't1', 'r1'
|
hbase> deleteall 't1', 'r1'
|
||||||
@ -31,13 +32,21 @@ a column and timestamp. Examples:
|
|||||||
hbase> deleteall 't1', 'r1', 'c1', ts1
|
hbase> deleteall 't1', 'r1', 'c1', ts1
|
||||||
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
||||||
|
|
||||||
|
ROWPREFIXFILTER can be used to delete row ranges
|
||||||
|
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}
|
||||||
|
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1' //delete certain column family in the row ranges
|
||||||
|
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1
|
||||||
|
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
||||||
|
|
||||||
|
CACHE can be used to specify how many deletes batched to be sent to server at one time, default is 100
|
||||||
|
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix', CACHE => 100}
|
||||||
|
|
||||||
|
|
||||||
The same commands also can be run on a table reference. Suppose you had a reference
|
The same commands also can be run on a table reference. Suppose you had a reference
|
||||||
t to table 't1', the corresponding command would be:
|
t to table 't1', the corresponding command would be:
|
||||||
|
|
||||||
hbase> t.deleteall 'r1'
|
|
||||||
hbase> t.deleteall 'r1', 'c1'
|
|
||||||
hbase> t.deleteall 'r1', 'c1', ts1
|
|
||||||
hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
hbase> t.deleteall 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
||||||
|
hbase> t.deleteall {ROWPREFIXFILTER => 'prefix', CACHE => 100}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
|
||||||
EOF
|
EOF
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,6 +120,10 @@ module Hbase
|
|||||||
|
|
||||||
@test_table.put(105, "x:a", "3")
|
@test_table.put(105, "x:a", "3")
|
||||||
@test_table.put(105, "x:a", "4")
|
@test_table.put(105, "x:a", "4")
|
||||||
|
|
||||||
|
@test_table.put("111", "x:a", "5")
|
||||||
|
@test_table.put("111", "x:b", "6")
|
||||||
|
@test_table.put("112", "x:a", "5")
|
||||||
end
|
end
|
||||||
|
|
||||||
def teardown
|
def teardown
|
||||||
@ -181,6 +185,14 @@ module Hbase
|
|||||||
assert_nil(res)
|
assert_nil(res)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
define_test "deletall should work with row prefix" do
|
||||||
|
@test_table.deleteall({ROWPREFIXFILTER => '11'})
|
||||||
|
res1 = @test_table._get_internal('111')
|
||||||
|
assert_nil(res1)
|
||||||
|
res2 = @test_table._get_internal('112')
|
||||||
|
assert_nil(res2)
|
||||||
|
end
|
||||||
|
|
||||||
define_test "append should work with value" do
|
define_test "append should work with value" do
|
||||||
@test_table.append("123", 'x:cnt2', '123')
|
@test_table.append("123", 'x:cnt2', '123')
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user