HBASE-813 Add a row counter in the new shell
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@685257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c41834a778
commit
802571af28
|
@ -15,6 +15,7 @@ Release 0.3.0 - Unreleased
|
||||||
HBASE-820 Need mainline to flush when 'Blocking updates' goes up.
|
HBASE-820 Need mainline to flush when 'Blocking updates' goes up.
|
||||||
(Jean-Daniel Cryans via Stack)
|
(Jean-Daniel Cryans via Stack)
|
||||||
HBASE-821 UnknownScanner happens too often (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
|
IMPROVEMENTS
|
||||||
|
|
|
@ -97,12 +97,15 @@ module Formatter
|
||||||
@out.printf(spec, str)
|
@out.printf(spec, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
def footer(startTime = nil)
|
def footer(startTime = nil, rowCount = nil)
|
||||||
|
if not rowCount
|
||||||
|
rowCount = @rowCount
|
||||||
|
end
|
||||||
if not startTime
|
if not startTime
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
# Only output elapsed time and row count if startTime passed
|
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
20
bin/HBase.rb
20
bin/HBase.rb
|
@ -346,6 +346,26 @@ module HBase
|
||||||
end
|
end
|
||||||
@formatter.footer(now)
|
@formatter.footer(now)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# Testing. To run this test, there needs to be an hbase cluster up and
|
# Testing. To run this test, there needs to be an hbase cluster up and
|
||||||
|
|
12
bin/hirb.rb
12
bin/hirb.rb
|
@ -114,6 +114,14 @@ HBASE SHELL COMMANDS:
|
||||||
|
|
||||||
hbase> alter 't1', {NAME => 'f1', VERSIONS => 5}
|
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
|
create Create table; pass table name, a dictionary of specifications per
|
||||||
column family, and optionally a dictionary of table configuration.
|
column family, and optionally a dictionary of table configuration.
|
||||||
Dictionaries are described below in the GENERAL NOTES section.
|
Dictionaries are described below in the GENERAL NOTES section.
|
||||||
|
@ -273,6 +281,10 @@ def deleteall(table, row, column = nil,
|
||||||
table(table).deleteall(row, column, timestamp)
|
table(table).deleteall(row, column, timestamp)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def count(table, interval = 1000)
|
||||||
|
table(table).count(interval)
|
||||||
|
end
|
||||||
|
|
||||||
# Output a banner message that tells users where to go for help
|
# Output a banner message that tells users where to go for help
|
||||||
puts <<HERE
|
puts <<HERE
|
||||||
HBase Shell; enter 'help<RETURN>' for list of supported commands.
|
HBase Shell; enter 'help<RETURN>' for list of supported commands.
|
||||||
|
|
Loading…
Reference in New Issue