jruby—统计hbase表中列族中的记录数

jdgnovmf  于 2021-06-09  发布在  Hbase
关注(0)|答案(1)|浏览(426)

我正在寻找一个hbase shell命令,它将计算指定列族中的记录数。我知道我能跑:

echo "scan 'table_name'" | hbase shell | grep column_family_name | wc -l

但是,这将比标准计数命令运行得慢得多:

count 'table_name' , CACHE => 50000 (because the use of the CACHE=>50000)

更糟糕的是,它不会返回实际的记录数,而是返回指定列族中的单元格总数(如果我没弄错的话)。我需要这样的东西:

count 'table_name' , CACHE => 50000 , {COLUMNS => 'column_family_name'}

提前谢谢,
迈克尔

xhv8bpkk

xhv8bpkk1#

这是我在需要的时候编写的ruby代码。提供了适当的意见。它为你提供 HBase 贝壳 count_table 命令。第一个参数是表名,第二个参数是属性数组,与的相同 scan shell命令。
你的问题的直接答案是

count_table 'your.table', { COLUMNS => 'your.family' }

我还建议添加缓存,如用于扫描:

count_table 'your.table', { COLUMNS => 'your.family', CACHE => 10000 }

以下是来源:


# 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

相关问题