Search in sources :

Example 6 with QualifierFilter

use of org.apache.hadoop.hbase.filter.QualifierFilter in project hbase by apache.

the class TestScannersWithFilters method testFilterList.

@Test
public void testFilterList() throws Exception {
    // Test getting a single row, single key using Row, Qualifier, and Value
    // regular expression and substring filters
    // Use must pass all
    List<Filter> filters = new ArrayList<>(3);
    filters.add(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
    filters.add(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
    filters.add(new ValueFilter(CompareOperator.EQUAL, new SubstringComparator("One")));
    Filter f = new FilterList(Operator.MUST_PASS_ALL, filters);
    Scan s = new Scan();
    s.addFamily(FAMILIES[0]);
    s.setFilter(f);
    KeyValue[] kvs = { new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]) };
    verifyScanFull(s, kvs);
    // Test getting everything with a MUST_PASS_ONE filter including row, qf,
    // val, regular expression and substring filters
    filters.clear();
    filters.add(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(".+Two.+")));
    filters.add(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
    filters.add(new ValueFilter(CompareOperator.EQUAL, new SubstringComparator("One")));
    f = new FilterList(Operator.MUST_PASS_ONE, filters);
    s = new Scan();
    s.setFilter(f);
    verifyScanNoEarlyOut(s, numRows, colsPerRow);
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) SubstringComparator(org.apache.hadoop.hbase.filter.SubstringComparator) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) KeyValue(org.apache.hadoop.hbase.KeyValue) InclusiveStopFilter(org.apache.hadoop.hbase.filter.InclusiveStopFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) PageFilter(org.apache.hadoop.hbase.filter.PageFilter) Filter(org.apache.hadoop.hbase.filter.Filter) ValueFilter(org.apache.hadoop.hbase.filter.ValueFilter) SkipFilter(org.apache.hadoop.hbase.filter.SkipFilter) ArrayList(java.util.ArrayList) ValueFilter(org.apache.hadoop.hbase.filter.ValueFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) Scan(org.apache.hadoop.hbase.client.Scan) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Example 7 with QualifierFilter

use of org.apache.hadoop.hbase.filter.QualifierFilter in project hbase by apache.

the class TestStoreScanner method testReadVersionWithRawAndFilter.

@Test
public void testReadVersionWithRawAndFilter() throws IOException {
    ScanInfo scanInfo = new ScanInfo(CONF, CF, 0, 1, Long.MAX_VALUE, KeepDeletedCells.FALSE, HConstants.DEFAULT_BLOCKSIZE, 0, CellComparator.getInstance(), false);
    KeyValue[] kvs = new KeyValue[] { create("R1", "cf", "a", 3, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "a", 2, KeyValue.Type.Put, "dont-care"), create("R1", "cf", "a", 1, KeyValue.Type.Put, "dont-care") };
    List<KeyValueScanner> scanners = Arrays.asList(new KeyValueScanner[] { new KeyValueScanFixture(CellComparator.getInstance(), kvs) });
    BinaryComparator comp = new BinaryComparator(Bytes.toBytes("a"));
    Filter filter = new QualifierFilter(CompareOperator.EQUAL, comp);
    Scan scanSpec = new Scan().withStartRow(Bytes.toBytes("R1")).readVersions(2).setRaw(true);
    scanSpec.setFilter(filter);
    try (StoreScanner scan = new StoreScanner(scanSpec, scanInfo, null, scanners)) {
        List<Cell> results = new ArrayList<>();
        assertEquals(true, scan.next(results));
        assertEquals(2, results.size());
    }
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) ColumnCountGetFilter(org.apache.hadoop.hbase.filter.ColumnCountGetFilter) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Filter(org.apache.hadoop.hbase.filter.Filter) Scan(org.apache.hadoop.hbase.client.Scan) Cell(org.apache.hadoop.hbase.Cell) Test(org.junit.Test)

Example 8 with QualifierFilter

use of org.apache.hadoop.hbase.filter.QualifierFilter in project hbase by apache.

the class TestAsyncTable method testCheckAndMutateWithTimestampFilter.

@Test
public void testCheckAndMutateWithTimestampFilter() throws Throwable {
    AsyncTable<?> table = getTable.get();
    // Put with specifying the timestamp
    table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();
    // Put with success
    CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
    assertTrue(result.isSuccess());
    assertNull(result.getResult());
    Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
    assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
    // Put with failure
    result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")))).get();
    assertFalse(result.isSuccess());
    assertNull(result.getResult());
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
Also used : FilterList(org.apache.hadoop.hbase.filter.FilterList) TimestampsFilter(org.apache.hadoop.hbase.filter.TimestampsFilter) FamilyFilter(org.apache.hadoop.hbase.filter.FamilyFilter) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Example 9 with QualifierFilter

use of org.apache.hadoop.hbase.filter.QualifierFilter in project hbase by apache.

the class TestScannersFromClientSide method testScanWithColumnsAndFilterAndVersion.

@Test
public void testScanWithColumnsAndFilterAndVersion() throws IOException {
    TableName tableName = name.getTableName();
    long now = EnvironmentEdgeManager.currentTime();
    try (Table table = TEST_UTIL.createTable(tableName, FAMILY, 4)) {
        for (int i = 0; i < 4; i++) {
            Put put = new Put(ROW);
            put.addColumn(FAMILY, QUALIFIER, now + i, VALUE);
            table.put(put);
        }
        Scan scan = new Scan();
        scan.addColumn(FAMILY, QUALIFIER);
        scan.setFilter(new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(QUALIFIER)));
        scan.readVersions(3);
        try (ResultScanner scanner = table.getScanner(scan)) {
            Result result = scanner.next();
            assertEquals(3, result.size());
        }
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) BinaryComparator(org.apache.hadoop.hbase.filter.BinaryComparator) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Example 10 with QualifierFilter

use of org.apache.hadoop.hbase.filter.QualifierFilter in project hbase by apache.

the class TestFromClientSide method testFilters.

@Test
public void testFilters() throws Exception {
    final TableName tableName = name.getTableName();
    try (Table ht = TEST_UTIL.createTable(tableName, FAMILY)) {
        byte[][] ROWS = makeN(ROW, 10);
        byte[][] QUALIFIERS = { Bytes.toBytes("col0-<d2v1>-<d3v2>"), Bytes.toBytes("col1-<d2v1>-<d3v2>"), Bytes.toBytes("col2-<d2v1>-<d3v2>"), Bytes.toBytes("col3-<d2v1>-<d3v2>"), Bytes.toBytes("col4-<d2v1>-<d3v2>"), Bytes.toBytes("col5-<d2v1>-<d3v2>"), Bytes.toBytes("col6-<d2v1>-<d3v2>"), Bytes.toBytes("col7-<d2v1>-<d3v2>"), Bytes.toBytes("col8-<d2v1>-<d3v2>"), Bytes.toBytes("col9-<d2v1>-<d3v2>") };
        for (int i = 0; i < 10; i++) {
            Put put = new Put(ROWS[i]);
            put.setDurability(Durability.SKIP_WAL);
            put.addColumn(FAMILY, QUALIFIERS[i], VALUE);
            ht.put(put);
        }
        Scan scan = new Scan();
        scan.addFamily(FAMILY);
        Filter filter = new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator("col[1-5]"));
        scan.setFilter(filter);
        try (ResultScanner scanner = ht.getScanner(scan)) {
            int expectedIndex = 1;
            for (Result result : scanner) {
                assertEquals(1, result.size());
                assertTrue(Bytes.equals(CellUtil.cloneRow(result.rawCells()[0]), ROWS[expectedIndex]));
                assertTrue(Bytes.equals(CellUtil.cloneQualifier(result.rawCells()[0]), QUALIFIERS[expectedIndex]));
                expectedIndex++;
            }
            assertEquals(6, expectedIndex);
        }
    }
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) TableName(org.apache.hadoop.hbase.TableName) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Filter(org.apache.hadoop.hbase.filter.Filter) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Aggregations

QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)21 Test (org.junit.Test)12 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)11 FilterList (org.apache.hadoop.hbase.filter.FilterList)11 Filter (org.apache.hadoop.hbase.filter.Filter)9 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)8 Scan (org.apache.hadoop.hbase.client.Scan)7 FamilyFilter (org.apache.hadoop.hbase.filter.FamilyFilter)6 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)6 TableName (org.apache.hadoop.hbase.TableName)5 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)5 InclusiveStopFilter (org.apache.hadoop.hbase.filter.InclusiveStopFilter)5 KeyValue (org.apache.hadoop.hbase.KeyValue)4 BinaryPrefixComparator (org.apache.hadoop.hbase.filter.BinaryPrefixComparator)4 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)4 TimestampsFilter (org.apache.hadoop.hbase.filter.TimestampsFilter)4 ValueFilter (org.apache.hadoop.hbase.filter.ValueFilter)4 Cell (org.apache.hadoop.hbase.Cell)3 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)3 KeyOnlyFilter (org.apache.hadoop.hbase.filter.KeyOnlyFilter)3