Search in sources :

Example 11 with RowKeyComparisonFilter

use of org.apache.phoenix.filter.RowKeyComparisonFilter in project phoenix by apache.

the class WhereOptimizerTest method testRVCExpressionWithSubsetOfPKCols.

/**
     * With only a subset of row key cols present (which includes the leading key), 
     * Phoenix should have optimized the start row for the scan to include the 
     * row keys cols that occur contiguously in the RVC.
     * 
     * Table entity_history has the row key defined as (organization_id, parent_id, created_date, entity_history_id). 
     * This test uses (organization_id, parent_id, entity_id) in RVC. So the start row should be comprised of
     * organization_id and parent_id.
     * @throws SQLException
     */
@Test
public void testRVCExpressionWithSubsetOfPKCols() throws SQLException {
    String tenantId = "000000000000001";
    String parentId = "000000000000002";
    String entityHistId = "000000000000003";
    String query = "select * from entity_history where (organization_id, parent_id, entity_history_id) >= (?,?,?)";
    List<Object> binds = Arrays.<Object>asList(tenantId, parentId, entityHistId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    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) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

Scan (org.apache.hadoop.hbase.client.Scan)11 Filter (org.apache.hadoop.hbase.filter.Filter)11 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)11 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)10 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)10 Test (org.junit.Test)10 SingleKeyValueComparisonFilter (org.apache.phoenix.filter.SingleKeyValueComparisonFilter)9 TestUtil.rowKeyFilter (org.apache.phoenix.util.TestUtil.rowKeyFilter)9 Date (java.sql.Date)4 PDate (org.apache.phoenix.schema.types.PDate)4 Expression (org.apache.phoenix.expression.Expression)2 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)2 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)2 AndExpression (org.apache.phoenix.expression.AndExpression)1 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)1 SubstrFunction (org.apache.phoenix.expression.function.SubstrFunction)1 KeyValueExpressionVisitor (org.apache.phoenix.expression.visitor.KeyValueExpressionVisitor)1 MultiCFCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiCFCQKeyValueComparisonFilter)1 MultiCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiCQKeyValueComparisonFilter)1 MultiEncodedCQKeyValueComparisonFilter (org.apache.phoenix.filter.MultiEncodedCQKeyValueComparisonFilter)1