HBASE-2314 [shell] Support for getting counters
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@922672 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
dd8456b1be
commit
a5715cc5d6
|
@ -430,6 +430,7 @@ Release 0.21.0 - Unreleased
|
|||
HBASE-2309 Add apache releases to pom (list of ) repositories
|
||||
(Kay Kay via Stack)
|
||||
HBASE-2279 Hbase Shell does not have any tests (Alexey Kovyrin via Stack)
|
||||
HBASE-2314 [shell] Support for getting counters (Alexey Kovyrin via Stack)
|
||||
|
||||
NEW FEATURES
|
||||
HBASE-1961 HBase EC2 scripts
|
||||
|
|
|
@ -170,6 +170,24 @@ module Hbase
|
|||
return ((block_given?) ? nil : res)
|
||||
end
|
||||
|
||||
#----------------------------------------------------------------------------------------------
|
||||
# Fetches and decodes a counter value from hbase
|
||||
def get_counter(row, column)
|
||||
family, qualifier = parse_column_name(column.to_s)
|
||||
# Format get request
|
||||
get = Get.new(row.to_s.to_java_bytes)
|
||||
get.addColumn(family, qualifier)
|
||||
get.setMaxVersions(1)
|
||||
|
||||
# Call hbase
|
||||
result = @table.get(get)
|
||||
return nil if result.isEmpty
|
||||
|
||||
# Fetch cell value
|
||||
cell = result.list.first
|
||||
Bytes::toLong(cell.getValue)
|
||||
end
|
||||
|
||||
#----------------------------------------------------------------------------------------------
|
||||
# Scans whole table or a range of keys and returns rows matching specific criterias
|
||||
def scan(args = {})
|
||||
|
|
|
@ -211,6 +211,7 @@ Shell.load_command_group(
|
|||
delete
|
||||
deleteall
|
||||
get
|
||||
get_counter
|
||||
incr
|
||||
put
|
||||
scan
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
module Shell
|
||||
module Commands
|
||||
class GetCounter < Command
|
||||
def help
|
||||
return <<-EOF
|
||||
Return a counter cell value at specified table/row/column coordinates.
|
||||
A cell cell should be managed with atomic increment function oh HBase
|
||||
and the data should be binary encoded. Example:
|
||||
|
||||
hbase> get_counter 't1', 'r1', 'c1'
|
||||
EOF
|
||||
end
|
||||
|
||||
def command(table, row, column, value = nil)
|
||||
if cnt = table(table).get_counter(row, column)
|
||||
puts "COUNTER VALUE = #{cnt}"
|
||||
else
|
||||
puts "No counter found at specified coordinates"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -14,9 +14,8 @@ module Shell
|
|||
end
|
||||
|
||||
def command(table, row, column, value = nil)
|
||||
format_simple_command do
|
||||
table(table).incr(row, column, value)
|
||||
end
|
||||
cnt = table(table).incr(row, column, value)
|
||||
puts "COUNTER VALUE = #{cnt}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -141,6 +141,17 @@ module Hbase
|
|||
define_test "incr should work with integer keys" do
|
||||
@test_table.incr(123, 'x:cnt3')
|
||||
end
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
define_test "get_counter should work with integer keys" do
|
||||
@test_table.incr(12345, 'x:cnt')
|
||||
assert_kind_of(Fixnum, @test_table.get_counter(12345, 'x:cnt'))
|
||||
end
|
||||
|
||||
define_test "get_counter should return nil for non-existent counters" do
|
||||
assert_nil(@test_table.get_counter(12345, 'x:qqqq'))
|
||||
end
|
||||
end
|
||||
|
||||
# Complex data management methods tests
|
||||
|
|
Loading…
Reference in New Issue