【问题标题】:Count number of records in a column family in an HBase table计算 HBase 表中列族中的记录数
【发布时间】:2014-10-28 00:06:45
【问题描述】:

我正在寻找一个 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'}

提前致谢,
迈克尔

【问题讨论】:

    标签: hbase jruby bigdata database nosql


    【解决方案1】:

    这是我在需要时编写的 Ruby 代码。提供适当的 cmets。它为您提供HBase shell 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
    

    【讨论】:

    • 你知道如何在HBase中添加这个功能吗?
    • 它只是客户端脚本,而不是您在 HBase 服务器中需要的东西。你不应该添加这样的东西,因为它的所有组件都已经在 HBase 中了。
    • 可以将类似上述count_table 的实用功能添加到~/.irbrc 文件中,以防用户需要跨多个hbase shell 会话。 .irbrc 文件与 IRB 使用的 rc 文件相同,即 Interacive Ruby Shell,但有一些细微差别 - hbase shell 实际上是 IRB 的 HBase 风格,它在 JRuby 上下文中运行,允许使用 Java 库。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 2018-02-15
    • 2013-09-16
    相关资源
    最近更新 更多