1

I'm trying to get an average value of some qualifier which is written as BigDecimal type in HBase for key rows with specific prefix.

 @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);
    }

I used fragment in code shared on https://www.programcreek.com/java-api-examples/class=org.apache.hadoop.hbase.client.coprocessor.AggregationClient&method=avg . In my case, I use SingleColumnValueFilter instead of PrefixFilter and when I initialise avg method, filter is not working. In case of using rowCount method which is also supported, SingleColumnValueFilter is taken into account and whole query works fine.

Here is my fragment:

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);

Why does filter not work ? My HBase version is 2.0.0, Hadoop 2.7.4

Michael
  • 11
  • 1

0 Answers0