Search in sources :

Example 36 with QueryPlan

use of org.apache.phoenix.compile.QueryPlan in project phoenix by apache.

the class ViewIT method testQueryViewStatementOptimization.

@Test
public void testQueryViewStatementOptimization() throws Exception {
    Connection conn = DriverManager.getConnection(getUrl());
    String sql = "CREATE TABLE " + fullTableName + " (k1 INTEGER NOT NULL, k2 INTEGER NOT NULL, v1 DECIMAL, CONSTRAINT pk PRIMARY KEY (k1, k2))" + tableDDLOptions;
    conn.createStatement().execute(sql);
    String fullViewName1 = "V_" + generateUniqueName();
    sql = "CREATE VIEW " + fullViewName1 + "  AS SELECT * FROM " + fullTableName;
    conn.createStatement().execute(sql);
    String fullViewName2 = "V_" + generateUniqueName();
    sql = "CREATE VIEW " + fullViewName2 + "  AS SELECT * FROM " + fullTableName + " WHERE k1 = 1.0";
    conn.createStatement().execute(sql);
    sql = "SELECT * FROM " + fullViewName1 + " order by k1, k2";
    PreparedStatement stmt = conn.prepareStatement(sql);
    QueryPlan plan = PhoenixRuntime.getOptimizedQueryPlan(stmt);
    assertEquals(0, plan.getOrderBy().getOrderByExpressions().size());
    sql = "SELECT * FROM " + fullViewName2 + " order by k1, k2";
    stmt = conn.prepareStatement(sql);
    plan = PhoenixRuntime.getOptimizedQueryPlan(stmt);
    assertEquals(0, plan.getOrderBy().getOrderByExpressions().size());
}
Also used : Connection(java.sql.Connection) PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PreparedStatement(java.sql.PreparedStatement) QueryPlan(org.apache.phoenix.compile.QueryPlan) Test(org.junit.Test)

Aggregations

QueryPlan (org.apache.phoenix.compile.QueryPlan)36 Connection (java.sql.Connection)19 PhoenixStatement (org.apache.phoenix.jdbc.PhoenixStatement)19 PreparedStatement (java.sql.PreparedStatement)12 ResultSet (java.sql.ResultSet)11 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)11 Test (org.junit.Test)11 Statement (java.sql.Statement)8 SQLException (java.sql.SQLException)7 PTable (org.apache.phoenix.schema.PTable)7 Date (java.sql.Date)6 Properties (java.util.Properties)6 ResultIterator (org.apache.phoenix.iterate.ResultIterator)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 KeyRange (org.apache.phoenix.query.KeyRange)4 PColumn (org.apache.phoenix.schema.PColumn)4 IOException (java.io.IOException)3 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)3 Pair (org.apache.hadoop.hbase.util.Pair)3