Index: bin/HBase.rb =================================================================== --- bin/HBase.rb (revision 685231) +++ bin/HBase.rb (working copy) @@ -346,6 +346,27 @@ 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.row([count.to_s + " rows in table."]) + @formatter.footer(now, count) + end + end # Testing. To run this test, there needs to be an hbase cluster up and Index: bin/Formatter.rb =================================================================== --- bin/Formatter.rb (revision 685231) +++ bin/Formatter.rb (working copy) @@ -97,12 +97,15 @@ @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 Index: bin/hirb.rb =================================================================== --- bin/hirb.rb (revision 685231) +++ bin/hirb.rb (working copy) @@ -113,6 +113,13 @@ 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. Current count is shown every 1000 rows. 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 +280,10 @@ 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.