【问题标题】:HBase Filter by value depending on another columnHBase 根据另一列按值过滤
【发布时间】:2016-02-05 05:36:48
【问题描述】:

我有一个看起来像这样的 Hbase 表

cf:col1 | cf:col2
----------------- 
   A    |   1
   A    |   2
   B    |   1
   B    |   2

我想根据 col1 的值过滤扫描结果。具体来说,我只想要(col1 是'A',col2 是'1')或(col1 是'B',col2 是'2')的记录。有没有办法使用标准过滤器来做到这一点?我正在通过 Java MapReduce 作业来完成这项工作。

【问题讨论】:

    标签: hbase


    【解决方案1】:

    您可以使用两个 SingleColumnValueFilter。

    Scan scan = new Scan();
    FilterList filterList = new FilterList();
    filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("col1"), CompareOp.NOT_EQUAL, Bytes.toBytes("1")));
    filterList.addFilter(new SingleColumnValueFilter(Bytes.toBytes("cf"), Bytes.toBytes("col2"), CompareOp.NOT_EQUAL, Bytes.toBytes("1")));
    //Set whether entire row should be filtered if column is not found.
    filter.setFilterIfMissing(false);
    scan.setFilter(filterList);
    

    从外壳

    scan 'yourTable' ,{ FILTER => "SingleColumnValueFilter('cf','col1',=, 'binary:1') AND SingleColumnValueFilter('cf','col2',=, 'binary:1')" } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多