diff --git a/CHANGES.txt b/CHANGES.txt index 7b04eb83a7f..5d773deb3d7 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -15,6 +15,7 @@ Release 0.3.0 - Unreleased HBASE-820 Need mainline to flush when 'Blocking updates' goes up. (Jean-Daniel Cryans via Stack) HBASE-821 UnknownScanner happens too often (Jean-Daniel Cryans via Stack) + HBASE-813 Add a row counter in the new shell (Jean-Daniel Cryans via Stack) IMPROVEMENTS diff --git a/bin/Formatter.rb b/bin/Formatter.rb index b0be20613c4..3af13d60a77 100644 --- a/bin/Formatter.rb +++ b/bin/Formatter.rb @@ -97,12 +97,15 @@ module Formatter @out.printf(spec, str) end - def footer(startTime = nil) + def footer(startTime = nil, rowCount = nil) + if not rowCount + rowCount = @rowCount + end if not startTime return end # Only output elapsed time and row count if startTime passed - @out.puts("%d row(s) in %.4f seconds" % [@rowCount, Time.now - startTime]) + @out.puts("%d row(s) in %.4f seconds" % [rowCount, Time.now - startTime]) end end diff --git a/bin/HBase.rb b/bin/HBase.rb index 836dbe2cae7..305ce321532 100644 --- a/bin/HBase.rb +++ b/bin/HBase.rb @@ -346,6 +346,26 @@ module HBase end @formatter.footer(now) end + + def count(interval = 1000) + now = Time.now + columns = getAllColumns() + cs = columns.to_java(java.lang.String) + s = @table.getScanner(cs) + count = 0 + i = s.iterator() + @formatter.header("Count may take a long time to complete!") + while i.hasNext() + r = i.next() + count += 1 + if count % interval == 0 + @formatter.row(["Current count: " + count.to_s + ", row: " + \ + (String.from_java_bytes r.getRow())]) + end + end + @formatter.footer(now, count) + end + end # Testing. To run this test, there needs to be an hbase cluster up and diff --git a/bin/hirb.rb b/bin/hirb.rb index 0687e409b7f..fe853561c57 100644 --- a/bin/hirb.rb +++ b/bin/hirb.rb @@ -113,6 +113,14 @@ HBASE SHELL COMMANDS: cell VERSIONS, do: hbase> alter 't1', {NAME => 'f1', VERSIONS => 5} + + count Count the number of rows in a table. This operation may take a LONG + time (Run '$HADOOP_HOME/bin/hadoop jar hbase.jar rowcount' to run a + counting mapreduce job). Current count is shown every 1000 rows by + default. Count interval may be optionally specified. Examples: + + hbase> count 't1' + hbase> count 't1', 100000 create Create table; pass table name, a dictionary of specifications per column family, and optionally a dictionary of table configuration. @@ -273,6 +281,10 @@ def deleteall(table, row, column = nil, table(table).deleteall(row, column, timestamp) end +def count(table, interval = 1000) + table(table).count(interval) +end + # Output a banner message that tells users where to go for help puts <' for list of supported commands.