use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testTableUsedWithQueryMore.
@Test
public void testTableUsedWithQueryMore() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE t (k1 CHAR(3) NOT NULL, k2 CHAR(15) NOT NULL, k3 DATE NOT NULL, k4 CHAR(15) NOT NULL, CONSTRAINT pk PRIMARY KEY (k1,k2,k3,k4))");
conn.createStatement().execute("CREATE INDEX idx ON t(k1,k3,k2,k4)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT * FROM t WHERE (k1,k2,k3,k4) > ('001','001xx000003DHml',to_date('2015-10-21 09:50:55.0'),'017xx0000022FuI')");
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testChooseTableForSelection.
@Test
public void testChooseTableForSelection() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
conn.createStatement().execute("CREATE INDEX idx ON t(v1)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT v1,v2 FROM t WHERE v1 = 'bar'");
// Choose T because v2 is not in index
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testChooseTableForSelectionStar.
@Test
public void testChooseTableForSelectionStar() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
conn.createStatement().execute("CREATE INDEX idx ON t(v1)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT * FROM t WHERE v1 = 'bar'");
// Choose T because v2 is not in index
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testOrderByNotDropped.
@Test
public void testOrderByNotDropped() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE foo (k VARCHAR NOT NULL PRIMARY KEY, v VARCHAR) IMMUTABLE_ROWS=true");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY v");
assertFalse(plan.getOrderBy().getOrderByExpressions().isEmpty());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testChooseTableForDynCols.
@Test
public void testChooseTableForDynCols() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE t (k INTEGER NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR) IMMUTABLE_ROWS=true");
conn.createStatement().execute("CREATE INDEX idx ON t(v1)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT k FROM t(v3 VARCHAR) WHERE v1 = 'bar'");
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
Aggregations