Search in sources :

Example 26 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testScanCaching_Default.

@Test
public void testScanCaching_Default() throws SQLException {
    String query = "select * from atable where a_integer=0";
    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();
    Configuration config = HBaseConfiguration.create();
    int defaultScannerCacheSize = config.getInt(HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
    assertEquals(defaultScannerCacheSize, pstmt.getFetchSize());
    assertEquals(defaultScannerCacheSize, scan.getCaching());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Scan(org.apache.hadoop.hbase.client.Scan) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 27 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testTenantConstraintsAddedToScan.

@Test
public void testTenantConstraintsAddedToScan() throws SQLException {
    String tenantTypeId = "5678";
    String tenantId = "000000000000123";
    String url = getUrl(tenantId);
    createTestTable(getUrl(), "create table base_table_for_tenant_filter_test (tenant_id char(15) not null, type_id char(4) not null, " + "id char(5) not null, a_integer integer, a_string varchar(100) constraint pk primary key (tenant_id, type_id, id)) multi_tenant=true");
    createTestTable(url, "create view tenant_filter_test (tenant_col integer) AS SELECT * FROM BASE_TABLE_FOR_TENANT_FILTER_TEST WHERE type_id= '" + tenantTypeId + "'");
    String query = "select * from tenant_filter_test where a_integer=0 and a_string='foo'";
    PhoenixConnection pconn = DriverManager.getConnection(url, 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();
    PTable table = plan.getTableRef().getTable();
    Expression aInteger = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_INTEGER").getPosition()).newColumnExpression();
    Expression aString = new ColumnRef(new TableRef(table), table.getColumnForColumnName("A_STRING").getPosition()).newColumnExpression();
    assertEquals(multiEncodedKVFilter(and(constantComparison(CompareOp.EQUAL, aInteger, 0), constantComparison(CompareOp.EQUAL, aString, "foo")), TWO_BYTE_QUALIFIERS), filter);
    byte[] startRow = PVarchar.INSTANCE.toBytes(tenantId + tenantTypeId);
    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) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) Expression(org.apache.phoenix.expression.Expression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Scan(org.apache.hadoop.hbase.client.Scan) ColumnRef(org.apache.phoenix.schema.ColumnRef) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) PTable(org.apache.phoenix.schema.PTable) TableRef(org.apache.phoenix.schema.TableRef) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 28 with PhoenixPreparedStatement

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

the class LimitCompilerTest method compileStatement.

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

Example 29 with PhoenixPreparedStatement

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

the class TestUtil method getSplits.

public static List<KeyRange> getSplits(Connection conn, String tableName, String pkCol, byte[] lowerRange, byte[] upperRange, String whereClauseSuffix, String selectClause) throws SQLException {
    String whereClauseStart = (lowerRange == null && upperRange == null ? "" : " WHERE " + ((lowerRange != null ? (pkCol + " >= ? " + (upperRange != null ? " AND " : "")) : "") + (upperRange != null ? (pkCol + " < ?") : "")));
    String whereClause = whereClauseSuffix == null ? whereClauseStart : whereClauseStart.length() == 0 ? (" WHERE " + whereClauseSuffix) : (" AND " + whereClauseSuffix);
    String query = "SELECT /*+ NO_INDEX */ " + selectClause + " FROM " + tableName + whereClause;
    PhoenixPreparedStatement pstmt = conn.prepareStatement(query).unwrap(PhoenixPreparedStatement.class);
    if (lowerRange != null) {
        pstmt.setBytes(1, lowerRange);
    }
    if (upperRange != null) {
        pstmt.setBytes(lowerRange != null ? 2 : 1, upperRange);
    }
    pstmt.execute();
    List<KeyRange> keyRanges = pstmt.getQueryPlan().getSplits();
    return keyRanges;
}
Also used : KeyRange(org.apache.phoenix.query.KeyRange) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement)

Example 30 with PhoenixPreparedStatement

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

the class WhereOptimizerTest method compileStatementTenantSpecific.

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

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