【问题标题】:How to get a latest sample record from hbase table (in last n hours)?如何从 hbase 表中获取最新的样本记录(最近 n 小时内)?
【发布时间】:2017-03-28 17:54:08
【问题描述】:

在大型 hbase 事务表中没有大量记录。

来自 Hbase shell:

  • 如何获取最近 6 次插入/更新的示例记录 小时?

  • 是否可以获取最后插入/更新记录的计数 6 小时?

【问题讨论】:

    标签: hbase


    【解决方案1】:
    • 如何获取最近 6 小时内插入/更新的样本记录?

      以下查询从 hbase 表中获取最近 6 小时内插入/更新的示例记录。

      scan 'my.table', { LIMIT =>1, TIMERANGE => [(Time.now.to_f.round()*1000).to_i-21600000, (Time.now.to_f.round()*1000).to_i]}

    • 是否可以获得最近 6 小时内插入/更新的记录数?

    基于 SO 答案:Count number of records in a column family in an HBase 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
    

    查询是:

    count_table 'my.table', { TIMERANGE => [(Time.now.to_f.round()*1000).to_i-21600000, (Time.now.to_f.round()*1000).to_i] , CACHE => 10000000}
    

    以上查询获取最近 6 小时内插入/更新记录的计数。

    它返回所需的结果,但尚未测试 w.r.t 性能负载。

    注意:虽然我已经回答了我的问题,但我仍然保留这个帖子 打开以从其他人那里获得更好的答案。

    【讨论】:

      猜你喜欢
      • 2012-09-04
      • 2015-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-08
      • 1970-01-01
      • 2020-09-12
      相关资源
      最近更新 更多