Search in sources :

Example 1 with PhoenixPreparedStatement

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

the class TestUtil method getGuidePostsList.

public static Collection<GuidePostsInfo> getGuidePostsList(Connection conn, String tableName, String pkCol, byte[] lowerRange, byte[] upperRange, String whereClauseSuffix) 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 */ COUNT(*) 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();
    TableRef tableRef = pstmt.getQueryPlan().getTableRef();
    PhoenixConnection pconn = conn.unwrap(PhoenixConnection.class);
    PTable table = tableRef.getTable();
    GuidePostsInfo info = pconn.getQueryServices().getTableStats(new GuidePostsKey(table.getName().getBytes(), SchemaUtil.getEmptyColumnFamily(table)));
    return Collections.singletonList(info);
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) GuidePostsKey(org.apache.phoenix.schema.stats.GuidePostsKey) GuidePostsInfo(org.apache.phoenix.schema.stats.GuidePostsInfo) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) TableRef(org.apache.phoenix.schema.TableRef) PTable(org.apache.phoenix.schema.PTable)

Example 2 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testPaddedRowKeyFilter.

@Test
public void testPaddedRowKeyFilter() throws SQLException {
    String keyPrefix = "fo";
    String query = "select * from atable where entity_id=?";
    List<Object> binds = Arrays.<Object>asList(keyPrefix);
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    bindParams(pstmt, binds);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    assertEquals(0, scan.getStartRow().length);
    assertEquals(0, scan.getStopRow().length);
    assertNotNull(scan.getFilter());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Scan(org.apache.hadoop.hbase.client.Scan) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 3 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testAndFilter.

@Test
public void testAndFilter() throws SQLException {
    String tenantId = "000000000000001";
    String query = "select * from atable where organization_id=? and a_integer=0 and a_string='foo'";
    List<Object> binds = Arrays.<Object>asList(tenantId);
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    bindParams(pstmt, binds);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    assertEquals(multiEncodedKVFilter(and(constantComparison(CompareOp.EQUAL, A_INTEGER, 0), constantComparison(CompareOp.EQUAL, A_STRING, "foo")), TWO_BYTE_QUALIFIERS), 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) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 4 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testAndPKAndNotPK.

@Test
public void testAndPKAndNotPK() throws SQLException {
    String query = "select * from bugTable where ID = 'i2' and company = 'c3'";
    PhoenixConnection pconn = DriverManager.getConnection(getUrl(), PropertiesUtil.deepCopy(TEST_PROPERTIES)).unwrap(PhoenixConnection.class);
    pconn.createStatement().execute("create table bugTable(ID varchar primary key,company varchar)");
    PhoenixPreparedStatement pstmt = newPreparedStatement(pconn, query);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    Filter filter = scan.getFilter();
    PColumn column = plan.getTableRef().getTable().getColumnForColumnName("COMPANY");
    assertEquals(singleKVFilter(constantComparison(CompareOp.EQUAL, new KeyValueColumnExpression(column), "c3")), filter);
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) 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) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 5 with PhoenixPreparedStatement

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

the class WhereCompilerTest method testScanCaching_CustomFetchSizeOnStatement.

@Test
public void testScanCaching_CustomFetchSizeOnStatement() 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);
    final int FETCH_SIZE = 25;
    pstmt.setFetchSize(FETCH_SIZE);
    QueryPlan plan = pstmt.optimizeQuery();
    Scan scan = plan.getContext().getScan();
    assertEquals(FETCH_SIZE, pstmt.getFetchSize());
    assertEquals(FETCH_SIZE, scan.getCaching());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) Scan(org.apache.hadoop.hbase.client.Scan) 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