use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testChooseTableOverIndex.
@Test
public void testChooseTableOverIndex() 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 FROM t WHERE k = 1");
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testMinMaxQualifierRangeWithOrderByOnKVColumn.
@Test
public void testMinMaxQualifierRangeWithOrderByOnKVColumn() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
String tableName = "testMintestMinMaxQualifierRange".toUpperCase();
conn.createStatement().execute("CREATE TABLE " + tableName + " (k INTEGER NOT NULL PRIMARY KEY, v1 INTEGER, v2 VARCHAR) COLUMN_ENCODED_BYTES=4");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
ResultSet rs = stmt.executeQuery("SELECT K from " + tableName + " ORDER BY (v1)");
assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE);
rs = stmt.executeQuery("SELECT K from " + tableName + " ORDER BY (v1, v2)");
assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
rs = stmt.executeQuery("SELECT V2 from " + tableName + " ORDER BY (v1)");
assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
rs = stmt.executeQuery("SELECT V1 from " + tableName + " ORDER BY (v1, v2)");
assertQualifierRanges(rs, ENCODED_EMPTY_COLUMN_NAME, ENCODED_CQ_COUNTER_INITIAL_VALUE + 1);
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testIndexHintParsing.
@Test
public void testIndexHintParsing() 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 idx1 ON t(v1) INCLUDE(v2)");
conn.createStatement().execute("CREATE INDEX idx2 ON t(v1,v2)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT /*+ INDEX(t idx3 idx4 \"idx5\") INDEX(t idx6 idx1) */ k FROM t WHERE v1 = 'foo' AND v2 = 'bar'");
assertEquals("IDX1", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testRVCAllColsForTableWithSecondaryIndexBasic.
@Test
public void testRVCAllColsForTableWithSecondaryIndexBasic() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE T (k VARCHAR NOT NULL PRIMARY KEY, v1 VARCHAR, v2 VARCHAR)");
conn.createStatement().execute("CREATE INDEX IDX ON T(v1, v2)");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
String query = "select * from t where (k, v1, v2) <= ('3', '1', '2')";
QueryPlan plan = stmt.optimizeQuery(query);
assertEquals("T", plan.getTableRef().getTable().getTableName().getString());
}
use of org.apache.phoenix.jdbc.PhoenixStatement in project phoenix by apache.
the class QueryOptimizerTest method testOrderByDroppedCompositeKey.
@Test
public void testOrderByDroppedCompositeKey() throws Exception {
Connection conn = DriverManager.getConnection(getUrl());
conn.createStatement().execute("CREATE TABLE foo (j INTEGER NOT NULL, k BIGINT NOT NULL, v VARCHAR CONSTRAINT pk PRIMARY KEY (j,k)) IMMUTABLE_ROWS=true");
PhoenixStatement stmt = conn.createStatement().unwrap(PhoenixStatement.class);
QueryPlan plan = stmt.optimizeQuery("SELECT * FROM foo ORDER BY j,k");
assertEquals(OrderBy.FWD_ROW_KEY_ORDER_BY, plan.getOrderBy());
}
Aggregations