Search in sources :

Example 76 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.

the class WhereOptimizerTest method testNullAtEndOfRVC.

@Test
public void testNullAtEndOfRVC() throws SQLException {
    String tenantId = "000000000000001";
    String parentId = "000000000000002";
    Date createdDate = null;
    String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?,?,?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, parentId, createdDate);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    byte[] expectedStartRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), PVarchar.INSTANCE.toBytes(parentId));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
Also used : RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleKeyValueComparisonFilter(org.apache.phoenix.filter.SingleKeyValueComparisonFilter) TestUtil.rowKeyFilter(org.apache.phoenix.util.TestUtil.rowKeyFilter) Scan(org.apache.hadoop.hbase.client.Scan) PDate(org.apache.phoenix.schema.types.PDate) Date(java.sql.Date) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 77 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.

the class WhereOptimizerTest method testNullAtStartOfRVC.

@Test
public void testNullAtStartOfRVC() throws SQLException {
    String tenantId = null;
    String parentId = "000000000000002";
    Date createdDate = new Date(System.currentTimeMillis());
    String query = "select * from entity_history where (organization_id, parent_id, created_date) >= (?,?,?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, parentId, createdDate);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    byte[] expectedStartRow = ByteUtil.concat(new byte[15], ByteUtil.previousKey(PChar.INSTANCE.toBytes(parentId)), PDate.INSTANCE.toBytes(createdDate));
    assertArrayEquals(expectedStartRow, scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
Also used : RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleKeyValueComparisonFilter(org.apache.phoenix.filter.SingleKeyValueComparisonFilter) TestUtil.rowKeyFilter(org.apache.phoenix.util.TestUtil.rowKeyFilter) Scan(org.apache.hadoop.hbase.client.Scan) PDate(org.apache.phoenix.schema.types.PDate) Date(java.sql.Date) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 78 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.

the class WhereOptimizerTest method testRVCWithCompareOpsForRowKeyColumnValuesSmallerThanSchema.

@Test
public void testRVCWithCompareOpsForRowKeyColumnValuesSmallerThanSchema() throws SQLException {
    String orgId = "0000005";
    String entityId = "011";
    String orgId2 = "000005";
    String entityId2 = "11";
    // CASE 1: >=
    String query = "select * from atable where (organization_id, entity_id) >= (?,?)";
    List<Object> binds = Arrays.<Object>asList(orgId, entityId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
    // CASE 2: >
    query = "select * from atable where (organization_id, entity_id) > (?,?)";
    binds = Arrays.<Object>asList(orgId, entityId);
    context = compileStatement(query, binds);
    scan = context.getScan();
    filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15))), scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
    // CASE 3: <=
    query = "select * from atable where (organization_id, entity_id) <= (?,?)";
    binds = Arrays.<Object>asList(orgId, entityId);
    context = compileStatement(query, binds);
    scan = context.getScan();
    filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
    assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15))), scan.getStopRow());
    // CASE 4: <
    query = "select * from atable where (organization_id, entity_id) < (?,?)";
    binds = Arrays.<Object>asList(orgId, entityId);
    context = compileStatement(query, binds);
    scan = context.getScan();
    filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStartRow());
    assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), scan.getStopRow());
    // CASE 5: =
    // For RVC, this will only occur if there's more than one key in the IN
    query = "select * from atable where (organization_id, entity_id) IN ((?,?),(?,?))";
    binds = Arrays.<Object>asList(orgId, entityId, orgId2, entityId2);
    context = compileStatement(query, binds);
    scan = context.getScan();
    filter = scan.getFilter();
    assertTrue(filter instanceof SkipScanFilter);
    ScanRanges scanRanges = context.getScanRanges();
    assertEquals(2, scanRanges.getPointLookupCount());
    Iterator<KeyRange> iterator = scanRanges.getPointLookupKeyIterator();
    KeyRange k1 = iterator.next();
    assertTrue(k1.isSingleKey());
    assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId), 15)), k1.getLowerRange());
    KeyRange k2 = iterator.next();
    assertTrue(k2.isSingleKey());
    assertArrayEquals(ByteUtil.concat(StringUtil.padChar(PChar.INSTANCE.toBytes(orgId2), 15), StringUtil.padChar(PChar.INSTANCE.toBytes(entityId2), 15)), k2.getLowerRange());
}
Also used : RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleKeyValueComparisonFilter(org.apache.phoenix.filter.SingleKeyValueComparisonFilter) TestUtil.rowKeyFilter(org.apache.phoenix.util.TestUtil.rowKeyFilter) KeyRange(org.apache.phoenix.query.KeyRange) Scan(org.apache.hadoop.hbase.client.Scan) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 79 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.

the class WhereOptimizerTest method testCombiningRVCUsingOr2.

@Test
public void testCombiningRVCUsingOr2() throws SQLException {
    String firstTenantId = "000000000000001";
    String secondTenantId = "000000000000005";
    String firstParentId = "000000000000011";
    String secondParentId = "000000000000015";
    String query = "select * from entity_history where (organization_id, parent_id) >= (?,?) OR (organization_id, parent_id) >= (?, ?)";
    List<Object> binds = Arrays.<Object>asList(firstTenantId, firstParentId, secondTenantId, secondParentId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstTenantId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
    assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
Also used : RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleKeyValueComparisonFilter(org.apache.phoenix.filter.SingleKeyValueComparisonFilter) TestUtil.rowKeyFilter(org.apache.phoenix.util.TestUtil.rowKeyFilter) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 80 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project phoenix by apache.

the class WhereOptimizerTest method testLikeExtractKeyExpression2.

@Test
public void testLikeExtractKeyExpression2() throws SQLException {
    String tenantId = "000000000000001";
    String keyPrefix = "002";
    String likeArg = keyPrefix + "_";
    String query = "select * from atable where organization_id = ? and entity_id  LIKE '" + likeArg + "'";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertEquals(rowKeyFilter(like(ENTITY_ID, likeArg, context)), filter);
    byte[] startRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(PVarchar.INSTANCE.toBytes(keyPrefix), 15));
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = ByteUtil.concat(PVarchar.INSTANCE.toBytes(tenantId), StringUtil.padChar(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(keyPrefix)), 15));
    assertArrayEquals(stopRow, scan.getStopRow());
}
Also used : RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleKeyValueComparisonFilter(org.apache.phoenix.filter.SingleKeyValueComparisonFilter) TestUtil.rowKeyFilter(org.apache.phoenix.util.TestUtil.rowKeyFilter) Scan(org.apache.hadoop.hbase.client.Scan) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

Filter (org.apache.hadoop.hbase.filter.Filter)179 Test (org.junit.Test)97 Scan (org.apache.hadoop.hbase.client.Scan)95 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)77 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)76 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)74 SingleKeyValueComparisonFilter (org.apache.phoenix.filter.SingleKeyValueComparisonFilter)45 TestUtil.rowKeyFilter (org.apache.phoenix.util.TestUtil.rowKeyFilter)45 FilterList (org.apache.hadoop.hbase.filter.FilterList)43 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)40 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)37 TestUtil.multiEncodedKVFilter (org.apache.phoenix.util.TestUtil.multiEncodedKVFilter)33 TestUtil.singleKVFilter (org.apache.phoenix.util.TestUtil.singleKVFilter)33 PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)31 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)27 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)25 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)24 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)24 ArrayList (java.util.ArrayList)22 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)18