diff --git a/hbase-shell/src/main/ruby/hbase/table.rb b/hbase-shell/src/main/ruby/hbase/table.rb index b5769ca..0f940b2 100644 --- a/hbase-shell/src/main/ruby/hbase/table.rb +++ b/hbase-shell/src/main/ruby/hbase/table.rb @@ -279,7 +279,7 @@ EOF #---------------------------------------------------------------------------------------------- # Get from table - def _get_internal(row, *args) + def _get_internal(row, stale = nil, *args) get = org.apache.hadoop.hbase.client.Get.new(row.to_s.to_java_bytes) maxlength = -1 @converters.clear() @@ -370,6 +370,11 @@ EOF result = @table.get(get) return nil if result.isEmpty + # Get stale info from result + unless stale == nil + stale[0] = result.isStale + end + # Print out results. Result can be Cell or RowResult. res = {} result.listCells.each do |c| @@ -488,7 +493,7 @@ EOF #---------------------------------------------------------------------------------------------- # Scans whole table or a range of keys and returns rows matching specific criteria - def _scan_internal(args = {}, scan = nil) + def _scan_internal(args = {}, scan = nil, stale = nil) raise(ArgumentError, "Args should be a Hash") unless args.kind_of?(Hash) raise(ArgumentError, "Scan argument should be org.apache.hadoop.hbase.client.Scan") \ unless scan == nil || scan.kind_of?(org.apache.hadoop.hbase.client.Scan) @@ -509,6 +514,10 @@ EOF while iter.hasNext row = iter.next key = org.apache.hadoop.hbase.util.Bytes::toStringBinary(row.getRow) + # Get stale from one row + if stale != nil + stale[0] = row.isStale + end row.listCells.each do |c| family = org.apache.hadoop.hbase.util.Bytes::toStringBinary(c.getFamilyArray, diff --git a/hbase-shell/src/main/ruby/shell/commands/get.rb b/hbase-shell/src/main/ruby/shell/commands/get.rb index 1ab13cb..d2ef420 100644 --- a/hbase-shell/src/main/ruby/shell/commands/get.rb +++ b/hbase-shell/src/main/ruby/shell/commands/get.rb @@ -83,12 +83,14 @@ EOF def get(table, row, *args) now = Time.now formatter.header(["COLUMN", "CELL"]) + stale = Array.new(1, false) - table._get_internal(row, *args) do |column, value| + table._get_internal(row, stale, *args) do |column, value| formatter.row([ column, value ]) end formatter.footer(now) + formatter.stale(stale[0]) 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..e810b2b 100644 --- a/hbase-shell/src/main/ruby/shell/commands/scan.rb +++ b/hbase-shell/src/main/ruby/shell/commands/scan.rb @@ -107,13 +107,19 @@ EOF now = Time.now formatter.header(["ROW", "COLUMN+CELL"]) + #used for getting stale info + stale_argu = Array.new(1, false) + stale = false + scan = table._hash_to_scan(args) #actually do the scanning - count = table._scan_internal(args, scan) do |row, cells| + count = table._scan_internal(args, scan, stale_argu) do |row, cells| formatter.row([ row, cells ]) + stale = stale || stale_argu end formatter.footer(now, count) + formatter.stale(stale[0]) # 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..43f5548 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(stale = false) + #if result is stale, output stale info + if stale == true + @out.print(" (possible stale results) ") + end end end