Java Code Examples for org.apache.phoenix.jdbc.PhoenixPreparedStatement#compileQuery()

The following examples show how to use org.apache.phoenix.jdbc.PhoenixPreparedStatement#compileQuery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HavingCompilerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static Expressions compileStatement(String query, List<Object> binds) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertTrue(plan instanceof AggregatePlan);
    Filter filter = plan.getContext().getScan().getFilter();
    assertTrue(filter == null || filter instanceof BooleanExpressionFilter);
    BooleanExpressionFilter boolFilter = (BooleanExpressionFilter)filter;
    AggregatePlan aggPlan = (AggregatePlan)plan;
    return new Expressions(boolFilter == null ? null : boolFilter.getExpression(), aggPlan.getHaving());
}
 
Example 2
Source File: QueryCompilerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private QueryPlan getQueryPlan(String query, List<Object> binds) throws SQLException {
    Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
    Connection conn = DriverManager.getConnection(getUrl(), props);
    try {
        PhoenixPreparedStatement statement = conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
        for (Object bind : binds) {
            statement.setObject(1, bind);
        }
        return statement.compileQuery(query);
    } finally {
        conn.close();
    }
}
 
Example 3
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static StatementContext compileStatement(String query, List<Object> binds, Integer limit) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    assertRoundtrip(query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertEquals(limit, plan.getLimit());
    return plan.getContext();
}
 
Example 4
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static StatementContext compileStatementTenantSpecific(String tenantId, String query, List<Object> binds) throws Exception {
	PhoenixConnection pconn = getTenantSpecificConnection("tenantId").unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    return  plan.getContext();
}
 
Example 5
Source File: StatementHintsCompilationTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static StatementContext compileStatement(String query, List<Object> binds, Integer limit) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertEquals(limit, plan.getLimit());
    return plan.getContext();
}
 
Example 6
Source File: HavingCompilerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static Expressions compileStatement(String query, List<Object> binds) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertTrue(plan instanceof AggregatePlan);
    Filter filter = plan.getContext().getScan().getFilter();
    assertTrue(filter == null || filter instanceof BooleanExpressionFilter);
    BooleanExpressionFilter boolFilter = (BooleanExpressionFilter)filter;
    AggregatePlan aggPlan = (AggregatePlan)plan;
    return new Expressions(boolFilter == null ? null : boolFilter.getExpression(), aggPlan.getHaving());
}
 
Example 7
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static StatementContext compileStatement(String query, List<Object> binds, Integer limit) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    assertRoundtrip(query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertEquals(limit, plan.getLimit());
    return plan.getContext();
}
 
Example 8
Source File: WhereOptimizerTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static StatementContext compileStatementTenantSpecific(String tenantId, String query, List<Object> binds) throws Exception {
	PhoenixConnection pconn = getTenantSpecificConnection("tenantId").unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    return  plan.getContext();
}
 
Example 9
Source File: StatementHintsCompilationTest.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private static QueryPlan compileStatement(String query, List<Object> binds, Integer limit) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    QueryPlan plan = pstmt.compileQuery();
    assertEquals(limit, plan.getLimit());
    return plan;
}
 
Example 10
Source File: SelectStatementRewriterTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static Filter compileStatement(String query) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.compileQuery();
    return plan.getContext().getScan().getFilter();
}
 
Example 11
Source File: LimitCompilerTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static QueryPlan compileStatement(String query, List<Object> binds) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    return pstmt.compileQuery();
}
 
Example 12
Source File: SelectStatementRewriterTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static Filter compileStatement(String query) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.compileQuery();
    return plan.getContext().getScan().getFilter();
}
 
Example 13
Source File: LimitCompilerTest.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private static QueryPlan compileStatement(String query, List<Object> binds) throws SQLException {
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = new PhoenixPreparedStatement(pconn, query);
    TestUtil.bindParams(pstmt, binds);
    return pstmt.compileQuery();
}