Search in sources :

Example 21 with PhoenixPreparedStatement

use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.

the class WhereCompilerTest method testAndTrueFilter.

@Test
public void testAndTrueFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer=0 and 2<3";
    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(singleKVFilter(constantComparison(CompareOp.EQUAL, A_INTEGER, 0)), filter);
    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId);
    assertArrayEquals(startRow, scan.getStartRow());
    byte[] stopRow = startRow;
    assertArrayEquals(ByteUtil.nextKey(stopRow), scan.getStopRow());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) TestUtil.multiEncodedKVFilter(org.apache.phoenix.util.TestUtil.multiEncodedKVFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) TestUtil.singleKVFilter(org.apache.phoenix.util.TestUtil.singleKVFilter) Scan(org.apache.hadoop.hbase.client.Scan) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 22 with PhoenixPreparedStatement

use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.

the class WhereCompilerTest method helpTestToNumberFilter.

private void helpTestToNumberFilter(String toNumberClause, BigDecimal expectedDecimal) throws Exception {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and x_decimal >= " + toNumberClause;
    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(singleKVFilter(constantComparison(CompareOp.GREATER_OR_EQUAL, X_DECIMAL, expectedDecimal)), filter);
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyComparisonFilter(org.apache.phoenix.filter.RowKeyComparisonFilter) TestUtil.multiEncodedKVFilter(org.apache.phoenix.util.TestUtil.multiEncodedKVFilter) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Filter(org.apache.hadoop.hbase.filter.Filter) TestUtil.singleKVFilter(org.apache.phoenix.util.TestUtil.singleKVFilter) Scan(org.apache.hadoop.hbase.client.Scan) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement)

Example 23 with PhoenixPreparedStatement

use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.

the class WhereCompilerTest method testTypeMismatch.

@Test
public void testTypeMismatch() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and a_integer > 'foo'";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    try {
        pstmt.optimizeQuery();
        fail();
    } catch (SQLException e) {
        assertTrue(e.getMessage().contains("Type mismatch"));
    }
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) SQLException(java.sql.SQLException) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 24 with PhoenixPreparedStatement

use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.

the class WhereOptimizerTest method compileStatement.

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();
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement)

Example 25 with PhoenixPreparedStatement

use of org.apache.phoenix.jdbc.PhoenixPreparedStatement in project phoenix by apache.

the class WhereCompilerTest method testFalseFilter.

@Test
public void testFalseFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id='" + tenantId + "' and 2=3";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    assertDegenerate(plan.getContext());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)54 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)51 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)41 Test (org.junit.Test)41 Scan (org.apache.hadoop.hbase.client.Scan)36 Filter (org.apache.hadoop.hbase.filter.Filter)29 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)28 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)28 TestUtil.multiEncodedKVFilter (org.apache.phoenix.util.TestUtil.multiEncodedKVFilter)28 TestUtil.singleKVFilter (org.apache.phoenix.util.TestUtil.singleKVFilter)28 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)5 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)5 Expression (org.apache.phoenix.expression.Expression)4 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)4 Connection (java.sql.Connection)3 FilterList (org.apache.hadoop.hbase.filter.FilterList)3 ColumnRef (org.apache.phoenix.schema.ColumnRef)3 PTable (org.apache.phoenix.schema.PTable)3 RowKeyValueAccessor (org.apache.phoenix.schema.RowKeyValueAccessor)3 TableRef (org.apache.phoenix.schema.TableRef)3