Search in sources :

Example 56 with Filter

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

the class WhereCompilerTest method testTenantConstraintsAddedToScan.

@Test
public void testTenantConstraintsAddedToScan() throws SQLException {
    String tenantTypeId = "5678";
    String tenantId = "000000000000123";
    String url = getUrl(tenantId);
    createTestTable(getUrl(), "create table base_table_for_tenant_filter_test (tenant_id char(15) not null, type_id char(4) not null, " + "id char(5) not null, a_integer integer, a_string varchar(100) constraint pk primary key (tenant_id, type_id, id)) multi_tenant=true");
    createTestTable(url, "create view tenant_filter_test (tenant_col integer) AS SELECT * FROM BASE_TABLE_FOR_TENANT_FILTER_TEST WHERE type_id= '" + tenantTypeId + "'");
    String query = "select * from tenant_filter_test where a_integer=0 and a_string='foo'";
    PhoenixConnection pconn = DriverManager.getConnection(url, PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    PTable table = plan.getTableRef().getTable();
    Expression aInteger = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
    Expression aString = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
    assertEquals(multiEncodedKVFilter(and(constantComparison(CompareOp.EQUAL, aInteger, 0), constantComparison(CompareOp.EQUAL, aString, "foo")), TWO_BYTE_QUALIFIERS), filter);
    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId + tenantTypeId);
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = startRow;
    assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) TestUtil.multiEncodedKVFilter(org.apache.phoenix.util.TestUtil.multiEncodedKVFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) TestUtil.singleKVFilter(org.apache.phoenix.util.TestUtil.singleKVFilter) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Scan(org.apache.hadoop.hbase.client.Scan) ColumnRef(org.apache.phoenix.schema.ColumnRef) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) PTable(org.apache.phoenix.schema.PTable) TableRef(org.apache.phoenix.schema.TableRef) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 57 with Filter

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

the class WhereOptimizerTest method testUsingRVCNonFullyQualifiedInClause.

@Test
public void testUsingRVCNonFullyQualifiedInClause() throws Exception {
    String firstOrgId = "000000000000001";
    String secondOrgId = "000000000000009";
    String firstParentId = "000000000000011";
    String secondParentId = "000000000000021";
    String query = "select * from entity_history where (organization_id, parent_id) IN ((?, ?), (?, ?))";
    List<Object> binds = Arrays.<Object>asList(firstOrgId, firstParentId, secondOrgId, secondParentId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertTrue(filter instanceof SkipScanFilter);
    assertArrayEquals(ByteUtil.concat(PVarchar.INSTANCE.toBytes(firstOrgId), PVarchar.INSTANCE.toBytes(firstParentId)), scan.getStartRow());
    assertArrayEquals(ByteUtil.nextKey(ByteUtil.concat(PVarchar.INSTANCE.toBytes(secondOrgId), PVarchar.INSTANCE.toBytes(secondParentId))), 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) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 58 with Filter

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

the class WhereOptimizerTest method testAndOrExpression.

@Test
public void testAndOrExpression() throws SQLException {
    String tenantId1 = "000000000000001";
    String tenantId2 = "000000000000003";
    String entityId1 = "002333333333331";
    String entityId2 = "002333333333333";
    String query = "select * from atable where (organization_id = ? and entity_id  = ?) or (organization_id = ? and entity_id  = ?)";
    List<Object> binds = Arrays.<Object>asList(tenantId1, entityId1, tenantId2, entityId2);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    ScanRanges scanRanges = context.getScanRanges();
    assertEquals(ScanRanges.EVERYTHING, scanRanges);
    assertArrayEquals(HConstants.EMPTY_START_ROW, 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)

Example 59 with Filter

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

the class WhereOptimizerTest method testGreaterThan.

@Test
public void testGreaterThan() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from entity_history where organization_id >?";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNull(filter);
    assertArrayEquals(ByteUtil.nextKey(PVarchar.INSTANCE.toBytes(tenantId)), 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 60 with Filter

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

the class WhereOptimizerTest method testRVCExpressionWithoutLeadingColOfRowKey.

/**
     * With the leading row key col missing Phoenix won't be able to optimize
     * and provide the start row for the scan.
     * 
     * Table entity_history has the row key defined as (organization_id, parent_id, created_date, entity_history_id). 
     * This test uses (parent_id, entity_id) in RVC. Start row should be empty.
     * @throws SQLException
     */
@Test
public void testRVCExpressionWithoutLeadingColOfRowKey() throws SQLException {
    String parentId = "000000000000002";
    String entityHistId = "000000000000003";
    String query = "select * from entity_history where (parent_id, entity_history_id) >= (?,?)";
    List<Object> binds = Arrays.<Object>asList(parentId, entityHistId);
    StatementContext context = compileStatement(query, binds);
    Scan scan = context.getScan();
    Filter filter = scan.getFilter();
    assertNotNull(filter);
    assertTrue(filter instanceof RowKeyComparisonFilter);
    assertArrayEquals(HConstants.EMPTY_START_ROW, 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

Filter (org.apache.hadoop.hbase.filter.Filter)172 Test (org.junit.Test)96 Scan (org.apache.hadoop.hbase.client.Scan)94 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 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)40 FilterList (org.apache.hadoop.hbase.filter.FilterList)39 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 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)24 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)23 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)22 ArrayList (java.util.ArrayList)19 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)18