use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.
the class WhereCompilerTest method testMultiColumnEqualFilter.
@Test
public void testMultiColumnEqualFilter() throws SQLException {
String tenantId = "000000000000001";
String query = "select * from atable where organization_id='" + tenantId + "' and a_string=b_string";
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), 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();
assertEquals(multiEncodedKVFilter(columnComparison(CompareOp.EQUAL, A_STRING, B_STRING), TWO_BYTE_QUALIFIERS), filter);
}
use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.
the class WhereCompilerTest method testInListWithAnd1Filter.
@Test
public void testInListWithAnd1Filter() throws SQLException {
String tenantId1 = "000000000000001";
String tenantId2 = "000000000000002";
String tenantId3 = "000000000000003";
String entityId = "00000000000000X";
String query = String.format("select * from %s where organization_id IN ('%s','%s','%s') AND entity_id='%s'", ATABLE_NAME, tenantId1, tenantId3, tenantId2, entityId);
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), 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();
assertEquals(new SkipScanFilter(ImmutableList.of(Arrays.asList(pointRange(tenantId1, entityId), pointRange(tenantId2, entityId), pointRange(tenantId3, entityId))), SchemaUtil.VAR_BINARY_SCHEMA), filter);
}
use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.
the class WhereCompilerTest method testDegenerateRowKeyFilter.
@Test
public void testDegenerateRowKeyFilter() throws SQLException {
String keyPrefix = "foobar";
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();
// Degenerate b/c "foobar" is more than 3 characters
assertDegenerate(plan.getContext());
}
use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.
the class WhereCompilerTest method testOrFilter.
@Test
public void testOrFilter() throws SQLException {
String tenantId = "000000000000001";
String keyPrefix = "foo";
int aInt = 2;
String query = "select * from atable where organization_id=? and (substr(entity_id,1,3)=? or a_integer=?)";
List<Object> binds = Arrays.<Object>asList(tenantId, keyPrefix, aInt);
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(singleKVFilter(or(constantComparison(CompareOp.EQUAL, new SubstrFunction(Arrays.<Expression>asList(new RowKeyColumnExpression(ENTITY_ID, new RowKeyValueAccessor(ATABLE.getPKColumns(), 1)), LiteralExpression.newConstant(1), LiteralExpression.newConstant(3))), keyPrefix), constantComparison(CompareOp.EQUAL, A_INTEGER, aInt))), filter);
}
use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.
the class WhereCompilerTest method testCollapseFunctionToNull.
@Test
public void testCollapseFunctionToNull() throws SQLException {
String query = "select * from atable where substr(entity_id,null) = 'foo'";
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), 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();
assertNull(filter);
assertArrayEquals(scan.getStartRow(), KeyRange.EMPTY_RANGE.getLowerRange());
assertArrayEquals(scan.getStopRow(), KeyRange.EMPTY_RANGE.getUpperRange());
}
Aggregations