use of org.apache.phoenix.filter.RowKeyComparisonFilter in project phoenix by apache.
the class WhereCompilerTest method testRowKeyFilter.
@Test
public void testRowKeyFilter() throws SQLException {
String keyPrefix = "foo";
String query = "select * from atable where substr(entity_id,1,3)=?";
List<Object> binds = Arrays.<Object>asList(keyPrefix);
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
bindParams(pstmt, binds);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
assertEquals(new RowKeyComparisonFilter(constantComparison(CompareOp.EQUAL, new SubstrFunction(Arrays.<Expression>asList(new RowKeyColumnExpression(ENTITY_ID, new RowKeyValueAccessor(ATABLE.getPKColumns(), 1)), LiteralExpression.newConstant(1), LiteralExpression.newConstant(3))), keyPrefix), QueryConstants.DEFAULT_COLUMN_FAMILY_BYTES), filter);
}
use of org.apache.phoenix.filter.RowKeyComparisonFilter 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());
}
use of org.apache.phoenix.filter.RowKeyComparisonFilter 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());
}
use of org.apache.phoenix.filter.RowKeyComparisonFilter in project phoenix by apache.
the class WhereOptimizerTest method testOrDiffColExpression.
@Test
public void testOrDiffColExpression() throws SQLException {
String tenantId1 = "000000000000001";
String entityId1 = "002333333333331";
String query = "select * from atable where organization_id = ? or entity_id = ?";
List<Object> binds = Arrays.<Object>asList(tenantId1, entityId1);
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());
}
use of org.apache.phoenix.filter.RowKeyComparisonFilter in project phoenix by apache.
the class WhereOptimizerTest method testUseOfFunctionOnLHSInRVC.
@Test
public void testUseOfFunctionOnLHSInRVC() throws SQLException {
String tenantId = "000000000000001";
String subStringTenantId = tenantId.substring(0, 3);
String parentId = "000000000000002";
Date createdDate = new Date(System.currentTimeMillis());
String query = "select * from entity_history where (substr(organization_id, 1, 3), parent_id, created_date) >= (?,?,?)";
List<Object> binds = Arrays.<Object>asList(subStringTenantId, parentId, createdDate);
StatementContext context = compileStatement(query, binds);
Scan scan = context.getScan();
Filter filter = scan.getFilter();
assertNotNull(filter);
assertTrue(filter instanceof RowKeyComparisonFilter);
byte[] expectedStartRow = PVarchar.INSTANCE.toBytes(subStringTenantId);
assertArrayEquals(expectedStartRow, scan.getStartRow());
assertArrayEquals(HConstants.EMPTY_END_ROW, scan.getStopRow());
}
Aggregations