use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class WhereCompilerTest method testAndFilter.
@Test
public void testAndFilter() throws SQLException {
String tenantId = "000000000000001";
String query = "select * from atable where organization_id=? and a_integer=0 and a_string='foo'";
List<Object> binds = Arrays.<Object>asList(tenantId);
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(multiEncodedKVFilter(and(constantComparison(CompareOp.EQUAL, A_INTEGER, 0), constantComparison(CompareOp.EQUAL, A_STRING, "foo")), TWO_BYTE_QUALIFIERS), filter);
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class WhereCompilerTest method testAndPKAndNotPK.
@Test
public void testAndPKAndNotPK() throws SQLException {
String query = "select * from bugTable where ID = 'i2' and company = 'c3'";
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
pconn.createStatement().execute("create table bugTable(ID varchar primary key,company varchar)");
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
Filter filter = scan.getFilter();
PColumn column = plan.getTableRef().getTable().getColumnForColumnName("COMPANY");
assertEquals(singleKVFilter(constantComparison(CompareOp.EQUAL, new KeyValueColumnExpression(column), "c3")), filter);
}
use of org.apache.phoenix.jdbc.PhoenixConnection in project phoenix by apache.
the class WhereCompilerTest method testScanCaching_CustomFetchSizeOnStatement.
@Test
public void testScanCaching_CustomFetchSizeOnStatement() throws SQLException {
String query = "select * from atable where a_integer=0";
PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
final int FETCH_SIZE = 25;
pstmt.setFetchSize(FETCH_SIZE);
QueryPlan plan = pstmt.optimizeQuery();
Scan scan = plan.getContext().getScan();
assertEquals(FETCH_SIZE, pstmt.getFetchSize());
assertEquals(FETCH_SIZE, scan.getCaching());
}
use of org.apache.phoenix.jdbc.PhoenixConnection 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.PhoenixConnection 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);
}
Aggregations