Search in sources :

Example 81 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-bigtable-hbase by googleapis.

the class AbstractTestFilters method testWhileMatchFilter_withUpdate.

@Test
public void testWhileMatchFilter_withUpdate() throws IOException {
    String rowKeyPrefix = dataHelper.randomString("wmf-wu-");
    byte[] qualA = dataHelper.randomData("qualA");
    Table table = addDataForTesting(rowKeyPrefix, qualA);
    table.put(new Put(Bytes.toBytes(rowKeyPrefix + "14")).addColumn(COLUMN_FAMILY, qualA, Bytes.toBytes(String.valueOf(2))));
    ByteArrayComparable valueComparable = new BinaryComparator(String.valueOf(2).getBytes());
    SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(COLUMN_FAMILY, qualA, CompareOp.NOT_EQUAL, valueComparable);
    Scan scan = new Scan().setFilter(new WhileMatchFilter(valueFilter));
    int[] expected = { 0, 1, 10, 11, 12, 13 };
    assertWhileMatchFilterResult(qualA, table, scan, expected);
}
Also used : ByteArrayComparable(org.apache.hadoop.hbase.filter.ByteArrayComparable) Table(org.apache.hadoop.hbase.client.Table) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) WhileMatchFilter(org.apache.hadoop.hbase.filter.WhileMatchFilter) Scan(org.apache.hadoop.hbase.client.Scan) Put(org.apache.hadoop.hbase.client.Put) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) Test(org.junit.Test)

Example 82 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-bigtable-hbase by googleapis.

the class TestSingleColumnValueFilter method testSup.

@Test
public void testSup() throws IOException {
    SingleColumnValueFilter filter = new SingleColumnValueFilter(COLUMN_FAMILY, QUALIFIER, CompareOp.GREATER_OR_EQUAL, Bytes.toBytes(5L));
    filter.setFilterIfMissing(true);
    Map<String, Long> rowKeys = getResult(filter);
    Assert.assertEquals(5, rowKeys.size());
    for (Entry<String, Long> entry : rowKeys.entrySet()) {
        checkKey(entry.getKey());
        Long v = entry.getValue();
        Assert.assertTrue(String.format("%d < 5", v), v >= 5);
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 83 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-bigtable-hbase by googleapis.

the class TestSingleColumnValueFilter method testStrictInf.

@Test
public void testStrictInf() throws IOException {
    SingleColumnValueFilter filter = new SingleColumnValueFilter(COLUMN_FAMILY, QUALIFIER, CompareOp.LESS, Bytes.toBytes(4L));
    filter.setFilterIfMissing(true);
    Map<String, Long> rowKeys = getResult(filter);
    Assert.assertEquals(4, rowKeys.size());
    for (Entry<String, Long> entry : rowKeys.entrySet()) {
        checkKey(entry.getKey());
        Long v = entry.getValue();
        Assert.assertTrue(String.format("%d >= 4", v), v < 4);
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 84 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-bigtable-hbase by googleapis.

the class TestSingleColumnValueFilter method testStrictSup.

@Test
public void testStrictSup() throws IOException {
    SingleColumnValueFilter filter = new SingleColumnValueFilter(COLUMN_FAMILY, QUALIFIER, CompareOp.GREATER, Bytes.toBytes(4L));
    filter.setFilterIfMissing(true);
    Map<String, Long> rowKeys = getResult(filter);
    Assert.assertEquals(5, rowKeys.size());
    for (Entry<String, Long> entry : rowKeys.entrySet()) {
        checkKey(entry.getKey());
        Long v = entry.getValue();
        Assert.assertTrue(String.format("%d <= 4", v), v > 4);
    }
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 85 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-bigtable-hbase by googleapis.

the class TestSingleColumnValueFilterAdapter method filterIfMissingIsApplied.

@Test
public void filterIfMissingIsApplied() throws IOException {
    String valueStr = "foobar";
    byte[] filterValue = Bytes.toBytes(valueStr);
    byte[] qualifier = Bytes.toBytes("someColumn");
    byte[] family = Bytes.toBytes("f");
    SingleColumnValueFilter filter = new SingleColumnValueFilter(family, qualifier, CompareFilter.CompareOp.EQUAL, new BinaryComparator(filterValue));
    filter.setFilterIfMissing(true);
    filter.setLatestVersionOnly(false);
    Filters.Filter adaptedFilter = UNDER_TEST.adapt(new FilterAdapterContext(new Scan(), null), filter);
    assertColumnSpecification(family, qualifier, false, adaptedFilter.toProto().getCondition().getPredicateFilter());
    Assert.assertEquals(createValueRangeFilter(valueStr), getValueRangeFilter(adaptedFilter.toProto().getCondition().getPredicateFilter().getChain()));
    Assert.assertEquals(FILTERS.pass().toProto(), adaptedFilter.toProto().getCondition().getTrueFilter());
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Scan(org.apache.hadoop.hbase.client.Scan) ByteString(com.google.protobuf.ByteString) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) Test(org.junit.Test)

Aggregations

SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)134 Test (org.junit.Test)64 FilterList (org.apache.hadoop.hbase.filter.FilterList)52 Scan (org.apache.hadoop.hbase.client.Scan)38 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)35 Result (org.apache.hadoop.hbase.client.Result)27 Filter (org.apache.hadoop.hbase.filter.Filter)26 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)21 Table (org.apache.hadoop.hbase.client.Table)21 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)19 Put (org.apache.hadoop.hbase.client.Put)18 ArrayList (java.util.ArrayList)13 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)12 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)11 IOException (java.io.IOException)10 Delete (org.apache.hadoop.hbase.client.Delete)10 ByteArrayComparable (org.apache.hadoop.hbase.filter.ByteArrayComparable)10 TableName (org.apache.hadoop.hbase.TableName)8 BitComparator (org.apache.hadoop.hbase.filter.BitComparator)7 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)7