hbase singlecolumnvaluefilter在aggregationclient的avg方法中不起作用

xqnpmsa8  于 2021-06-09  发布在  Hbase
关注(0)|答案(0)|浏览(298)

我试图获取某个限定符的平均值,该限定符在hbase中被写成bigdecimal类型,用于具有特定前缀的键行。

@Test(timeout = 300000)
    public void testAvgWithFilter() throws Throwable {
    AggregationClient aClient = new AggregationClient(conf);
    Scan scan = new Scan();
    scan.addColumn(TEST_FAMILY, TEST_QUALIFIER);
    Filter f = new PrefixFilter(Bytes.toBytes("foo:bar"));
    scan.setFilter(f);
    final ColumnInterpreter<Double, Double, EmptyMsg, DoubleMsg, DoubleMsg>       ci = new DoubleColumnInterpreter();
    Double avg = null;
    avg = aClient.avg(TEST_TABLE, ci, scan);
    assertEquals(Double.NaN, avg, 0);
    }

我在共享的代码中使用了片段https://www.programcreek.com/java-api-examples/class=org.apache.hadoop.hbase.client.coprocessor.aggregationclient&method=avg . 在我的例子中,我使用singlecolumnvaluefilter而不是prefixfilter,当我初始化avg方法时,filter不起作用。在使用同样支持的rowcount方法的情况下,考虑了singlecolumnvaluefilter,整个查询工作正常。
这是我的片段:

AggregationClient aggClient = new AggregationClient(conf);
            Table table = connection.getTable(TableName.valueOf(Bytes.toBytes(tableName)));

          Scan scan = new Scan();
          scan.addFamily(Bytes.toBytes(columnFamily));
          scan.setRowPrefixFilter(Bytes.toBytes(rowKeyPrefix));

            FilterList filterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);

            SingleColumnValueFilter filter1 = new SingleColumnValueFilter(
                    Bytes.toBytes(columnFamily),
                    Bytes.toBytes("columName"),
                    CompareOperator.EQUAL,
                    new BinaryComparator(Bytes.toBytes(searchValue1))
            );

            SingleColumnValueFilter filter2 = new SingleColumnValueFilter(
                    Bytes.toBytes(columnFamily),
                    Bytes.toBytes("columnName"),
                    CompareOperator.EQUAL,
                    new BinaryComparator(Bytes.toBytes(searchValue2))
            );

              SingleColumnValueFilter[] filters = {
                      filter1
                      filter2

              };

              for (Filter f : filters) {
                  filterList.addFilter(f);
              }

              scan.setFilter(filterList);

              scan.addColumn(Bytes.toBytes(columnFamily), Bytes.toBytes("sog"));

            final ColumnInterpreter<BigDecimal,
                    BigDecimal,
                    HBaseProtos.EmptyMsg,
                    HBaseProtos.BigDecimalMsg,
                    HBaseProtos.BigDecimalMsg> columnInterpreter =
                    new BigDecimalColumnInterpreter();

            Double avgx = null;
            avgx = aggClient.avg(table, ci, scan);

为什么过滤器不工作?我的hbase版本是2.0.0,hadoop 2.7.4

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题