Search in sources :

Example 1 with MatchCode

use of org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode in project hbase by apache.

the class TestUserScanQueryMatcher method testMatch_Wildcard.

@Test
public void testMatch_Wildcard() throws IOException {
    // Moving up from the Tracker by using Gets and List<KeyValue> instead
    // of just byte []
    // Expected result
    List<MatchCode> expected = new ArrayList<>(6);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.DONE);
    long now = EnvironmentEdgeManager.currentTime();
    UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE, 0, rowComparator), null, now - ttl, now, null);
    List<KeyValue> memstore = new ArrayList<>(6);
    memstore.add(new KeyValue(row1, fam2, col1, 1, data));
    memstore.add(new KeyValue(row1, fam2, col2, 1, data));
    memstore.add(new KeyValue(row1, fam2, col3, 1, data));
    memstore.add(new KeyValue(row1, fam2, col4, 1, data));
    memstore.add(new KeyValue(row1, fam2, col5, 1, data));
    memstore.add(new KeyValue(row2, fam1, col1, 1, data));
    List<ScanQueryMatcher.MatchCode> actual = new ArrayList<>(memstore.size());
    KeyValue k = memstore.get(0);
    qm.setToNewRow(k);
    for (KeyValue kv : memstore) {
        actual.add(qm.match(kv));
    }
    assertEquals(expected.size(), actual.size());
    for (int i = 0; i < expected.size(); i++) {
        LOG.debug("expected " + expected.get(i) + ", actual " + actual.get(i));
        assertEquals(expected.get(i), actual.get(i));
    }
}
Also used : MatchCode(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ScanInfo(org.apache.hadoop.hbase.regionserver.ScanInfo) Test(org.junit.Test)

Example 2 with MatchCode

use of org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode in project hbase by apache.

the class TestUserScanQueryMatcher method testMatch_ExpiredExplicit.

/**
   * Verify that {@link ScanQueryMatcher} only skips expired KeyValue instances and does not exit
   * early from the row (skipping later non-expired KeyValues). This version mimics a Get with
   * explicitly specified column qualifiers.
   * @throws IOException
   */
@Test
public void testMatch_ExpiredExplicit() throws IOException {
    long testTTL = 1000;
    MatchCode[] expected = new MatchCode[] { ScanQueryMatcher.MatchCode.SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.INCLUDE_AND_SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.SEEK_NEXT_ROW, ScanQueryMatcher.MatchCode.DONE };
    long now = EnvironmentEdgeManager.currentTime();
    UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 0, 1, testTTL, KeepDeletedCells.FALSE, 0, rowComparator), get.getFamilyMap().get(fam2), now - testTTL, now, null);
    KeyValue[] kvs = new KeyValue[] { new KeyValue(row1, fam2, col1, now - 100, data), new KeyValue(row1, fam2, col2, now - 50, data), new KeyValue(row1, fam2, col3, now - 5000, data), new KeyValue(row1, fam2, col4, now - 500, data), new KeyValue(row1, fam2, col5, now - 10000, data), new KeyValue(row2, fam1, col1, now - 10, data) };
    KeyValue k = kvs[0];
    qm.setToNewRow(k);
    List<MatchCode> actual = new ArrayList<>(kvs.length);
    for (KeyValue kv : kvs) {
        actual.add(qm.match(kv));
    }
    assertEquals(expected.length, actual.size());
    for (int i = 0; i < expected.length; i++) {
        LOG.debug("expected " + expected[i] + ", actual " + actual.get(i));
        assertEquals(expected[i], actual.get(i));
    }
}
Also used : MatchCode(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ScanInfo(org.apache.hadoop.hbase.regionserver.ScanInfo) Test(org.junit.Test)

Example 3 with MatchCode

use of org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode in project hbase by apache.

the class TestScanWildcardColumnTracker method testCheckColumnEnforceVersions.

@Test
public void testCheckColumnEnforceVersions() throws IOException {
    ScanWildcardColumnTracker tracker = new ScanWildcardColumnTracker(0, VERSIONS, Long.MIN_VALUE);
    // Create list of qualifiers
    List<byte[]> qualifiers = new ArrayList<>(4);
    qualifiers.add(Bytes.toBytes("qualifier1"));
    qualifiers.add(Bytes.toBytes("qualifier1"));
    qualifiers.add(Bytes.toBytes("qualifier1"));
    qualifiers.add(Bytes.toBytes("qualifier2"));
    // Setting up expected result
    List<ScanQueryMatcher.MatchCode> expected = new ArrayList<>(4);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    expected.add(ScanQueryMatcher.MatchCode.SEEK_NEXT_COL);
    expected.add(ScanQueryMatcher.MatchCode.INCLUDE);
    List<MatchCode> actual = new ArrayList<>(qualifiers.size());
    long timestamp = 0;
    for (byte[] qualifier : qualifiers) {
        MatchCode mc = ScanQueryMatcher.checkColumn(tracker, qualifier, 0, qualifier.length, ++timestamp, KeyValue.Type.Put.getCode(), false);
        actual.add(mc);
    }
    // Compare actual with expected
    for (int i = 0; i < expected.size(); i++) {
        assertEquals(expected.get(i), actual.get(i));
    }
}
Also used : MatchCode(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with MatchCode

use of org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode in project hbase by apache.

the class TestUserScanQueryMatcher method testMatch_ExpiredWildcard.

/**
   * Verify that {@link ScanQueryMatcher} only skips expired KeyValue instances and does not exit
   * early from the row (skipping later non-expired KeyValues). This version mimics a Get with
   * wildcard-inferred column qualifiers.
   * @throws IOException
   */
@Test
public void testMatch_ExpiredWildcard() throws IOException {
    long testTTL = 1000;
    MatchCode[] expected = new MatchCode[] { ScanQueryMatcher.MatchCode.INCLUDE, ScanQueryMatcher.MatchCode.INCLUDE, ScanQueryMatcher.MatchCode.SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.INCLUDE, ScanQueryMatcher.MatchCode.SEEK_NEXT_COL, ScanQueryMatcher.MatchCode.DONE };
    long now = EnvironmentEdgeManager.currentTime();
    UserScanQueryMatcher qm = UserScanQueryMatcher.create(scan, new ScanInfo(this.conf, fam2, 0, 1, testTTL, KeepDeletedCells.FALSE, 0, rowComparator), null, now - testTTL, now, null);
    KeyValue[] kvs = new KeyValue[] { new KeyValue(row1, fam2, col1, now - 100, data), new KeyValue(row1, fam2, col2, now - 50, data), new KeyValue(row1, fam2, col3, now - 5000, data), new KeyValue(row1, fam2, col4, now - 500, data), new KeyValue(row1, fam2, col5, now - 10000, data), new KeyValue(row2, fam1, col1, now - 10, data) };
    KeyValue k = kvs[0];
    qm.setToNewRow(k);
    List<ScanQueryMatcher.MatchCode> actual = new ArrayList<>(kvs.length);
    for (KeyValue kv : kvs) {
        actual.add(qm.match(kv));
    }
    assertEquals(expected.length, actual.size());
    for (int i = 0; i < expected.length; i++) {
        LOG.debug("expected " + expected[i] + ", actual " + actual.get(i));
        assertEquals(expected[i], actual.get(i));
    }
}
Also used : MatchCode(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ScanInfo(org.apache.hadoop.hbase.regionserver.ScanInfo) Test(org.junit.Test)

Example 5 with MatchCode

use of org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode in project hbase by apache.

the class TestCompactionScanQueryMatcher method testDropDeletes.

private void testDropDeletes(byte[] from, byte[] to, byte[][] rows, MatchCode... expected) throws IOException {
    long now = EnvironmentEdgeManager.currentTime();
    // Set time to purge deletes to negative value to avoid it ever happening.
    ScanInfo scanInfo = new ScanInfo(this.conf, fam2, 0, 1, ttl, KeepDeletedCells.FALSE, -1L, rowComparator);
    CompactionScanQueryMatcher qm = CompactionScanQueryMatcher.create(scanInfo, ScanType.COMPACT_RETAIN_DELETES, Long.MAX_VALUE, HConstants.OLDEST_TIMESTAMP, HConstants.OLDEST_TIMESTAMP, now, from, to, null);
    List<ScanQueryMatcher.MatchCode> actual = new ArrayList<>(rows.length);
    byte[] prevRow = null;
    for (byte[] row : rows) {
        if (prevRow == null || !Bytes.equals(prevRow, row)) {
            qm.setToNewRow(KeyValueUtil.createFirstOnRow(row));
            prevRow = row;
        }
        actual.add(qm.match(new KeyValue(row, fam2, null, now, Type.Delete)));
    }
    assertEquals(expected.length, actual.size());
    for (int i = 0; i < expected.length; i++) {
        LOG.debug("expected " + expected[i] + ", actual " + actual.get(i));
        assertEquals(expected[i], actual.get(i));
    }
}
Also used : MatchCode(org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode) KeyValue(org.apache.hadoop.hbase.KeyValue) ArrayList(java.util.ArrayList) ScanInfo(org.apache.hadoop.hbase.regionserver.ScanInfo)

Aggregations

MatchCode (org.apache.hadoop.hbase.regionserver.querymatcher.ScanQueryMatcher.MatchCode)8 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)7 KeyValue (org.apache.hadoop.hbase.KeyValue)6 ScanInfo (org.apache.hadoop.hbase.regionserver.ScanInfo)6 Cell (org.apache.hadoop.hbase.Cell)1