From fa713d8042351d06533358947ea0cd3228f99973 Mon Sep 17 00:00:00 2001 From: Lars George Date: Sat, 28 Mar 2015 10:46:23 +0100 Subject: [PATCH] HBASE-10728 get_counter value is never used. --- hbase-shell/src/main/ruby/hbase/table.rb | 7 ++++++- hbase-shell/src/main/ruby/shell/commands/get_counter.rb | 10 +++++----- hbase-shell/src/main/ruby/shell/commands/incr.rb | 6 +++++- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index 23e9a9d..9a71fa5 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -219,7 +219,12 @@ EOF set_op_ttl(incr, ttl) if ttl end incr.addColumn(family, qualifier, value) - @table.increment(incr) + result = @table.increment(incr) + return nil if result.isEmpty + + # Fetch cell value + cell = result.listCells[0] + org.apache.hadoop.hbase.util.Bytes::toLong(cell.getValue) end #---------------------------------------------------------------------------------------------- diff --git a/hbase-shell/src/main/ruby/shell/commands/get_counter.rb b/hbase-shell/src/main/ruby/shell/commands/get_counter.rb index 00cf64d..6708c6a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get_counter.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get_counter.rb @@ -23,8 +23,8 @@ module Shell 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: +A counter cell should be managed with atomic increment functions on HBase +and the data should be binary encoded (as long value). Example: hbase> get_counter 'ns1:t1', 'r1', 'c1' hbase> get_counter 't1', 'r1', 'c1' @@ -36,11 +36,11 @@ t to table 't1', the corresponding command would be: EOF end - def command(table, row, column, value) - get_counter(table(table), row, column, value) + def command(table, row, column) + get_counter(table(table), row, column) end - def get_counter(table, row, column, value = nil) + def get_counter(table, row, column) if cnt = table._get_counter_internal(row, column) puts "COUNTER VALUE = #{cnt}" else diff --git a/hbase-shell/src/main/ruby/shell/commands/incr.rb b/hbase-shell/src/main/ruby/shell/commands/incr.rb index a59869c..d223a45 100644 --- a/hbase-shell/src/main/ruby/shell/commands/incr.rb +++ b/hbase-shell/src/main/ruby/shell/commands/incr.rb @@ -50,7 +50,11 @@ EOF def incr(table, row, column, value = nil, args={}) format_simple_command do - table._incr_internal(row, column, value, args) + if cnt = table._incr_internal(row, column, value, args) + puts "COUNTER VALUE = #{cnt}" + else + puts "No counter found at specified coordinates" + end end end end -- 2.1.3