diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index b5769ca..227555f 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -370,6 +370,9 @@ EOF result = @table.get(get) return nil if result.isEmpty + # Get stale info from results + is_stale = result.isStale + # Print out results. Result can be Cell or RowResult. res = {} result.listCells.each do |c| @@ -389,7 +392,7 @@ EOF end # If block given, we've yielded all the results, otherwise just return them - return ((block_given?) ? nil : res) + return ((block_given?) ? is_stale : res) end #---------------------------------------------------------------------------------------------- @@ -509,6 +512,7 @@ EOF while iter.hasNext row = iter.next key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow) + is_stale = row.isStale row.listCells.each do |c| family = org.apache.hadoop.hbase.util.Bytes::toStringBinary(c.getFamilyArray, @@ -536,7 +540,7 @@ EOF end scanner.close() - return ((block_given?) ? count : res) + return ((block_given?) ? [count, is_stale] : res) end # Apply OperationAttributes to puts/scans/gets diff --git a/hbase-shell/src/main/ruby/shell/commands/get.rb b/hbase-shell/src/main/ruby/shell/commands/get.rb index 1ab13cb..683bc65 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get.rb @@ -84,11 +84,12 @@ EOF now = Time.now formatter.header(["COLUMN", "CELL"]) - table._get_internal(row, *args) do |column, value| + is_stale = table._get_internal(row, *args) do |column, value| formatter.row([ column, value ]) end formatter.footer(now) + formatter.stale(is_stale) end end end diff --git a/hbase-shell/src/main/ruby/shell/commands/scan.rb b/hbase-shell/src/main/ruby/shell/commands/scan.rb index 6f49f80..6b65f6a 100644 --- a/hbase-shell/src/main/ruby/shell/commands/scan.rb +++ b/hbase-shell/src/main/ruby/shell/commands/scan.rb @@ -109,11 +109,12 @@ EOF scan = table._hash_to_scan(args) #actually do the scanning - count = table._scan_internal(args, scan) do |row, cells| + count, is_stale = table._scan_internal(args, scan) do |row, cells| formatter.row([ row, cells ]) end formatter.footer(now, count) + formatter.stale(is_stale) # if scan metrics were enabled, print them after the results if (scan != nil && scan.isScanMetricsEnabled()) diff --git a/hbase-shell/src/main/ruby/shell/formatter.rb b/hbase-shell/src/main/ruby/shell/formatter.rb index 47c9c8d..0705a98 100644 --- a/hbase-shell/src/main/ruby/shell/formatter.rb +++ b/hbase-shell/src/main/ruby/shell/formatter.rb @@ -181,7 +181,14 @@ module Shell return unless start_time row_count ||= @row_count # Only output elapsed time and row count if startTime passed - @out.puts("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time]) + @out.print("%d row(s) in %.4f seconds" % [row_count, Time.now - start_time]) + end + + def stale(is_stale = false) + #if result is stale, output stale info + if is_stale == true + @out.print(" (possible stale results) ") + end end end