更新时间:2023-11-30 22:50:10
这里是我在需要时写的Ruby代码需要。提供适当的意见。它为您提供 HBase
shell count_table
命令。第一个参数是表名,第二个是属性数组,与 scan
shell命令相同。
Here is Ruby code I have written when needed thing like you need. Appropriate comments are provided. It provides you with HBase
shell count_table
command. First parameter is table name and second is array of properties, the same as for scan
shell command.
您的问题是
count_table 'your.table', { COLUMNS => 'your.family' }
我也建议添加缓存,
I also recommend to add cache, like for scan:
count_table 'your.table', { COLUMNS => 'your.family', CACHE => 10000 }
在这里你可以使用来源:
And here you go with sources:
# Argiments are the same as for scan command.
# Examples:
#
# count_table 'test.table', { COLUMNS => 'f:c1' }
# --- Counts f:c1 columsn in 'test_table'.
#
# count_table 'other.table', { COLUMNS => 'f' }
# --- Counts 'f' family rows in 'other.table'.
#
# count_table 'test.table', { CACHE => 1000 }
# --- Count rows with caching.
#
def count_table(tablename, args = {})
table = @shell.hbase_table(tablename)
# Run the scanner
scanner = table._get_scanner(args)
count = 0
iter = scanner.iterator
# Iterate results
while iter.hasNext
row = iter.next
count += 1
end
# Return the counter
return count
end