Search in sources :

Example 6 with RowKeyValueAccessor

use of org.apache.phoenix.schema.RowKeyValueAccessor in project phoenix by apache.

the class HavingCompilerTest method testOrAggFuncInHaving.

@Test
public void testOrAggFuncInHaving() throws SQLException {
    String query = "select count(1) from atable group by a_string having count(1) >= 1 or a_string = 'foo'";
    List<Object> binds = Collections.emptyList();
    Expressions expressions = compileStatement(query, binds);
    PColumn aCol = ATABLE.getColumnForColumnName("A_STRING");
    Expression h = or(constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(), 1L), constantComparison(CompareOp.EQUAL, new // a_string comes from group by key in this case
    RowKeyColumnExpression(// a_string comes from group by key in this case
    aCol, new RowKeyValueAccessor(Arrays.<PColumn>asList(aCol), 0)), "foo"));
    assertNull(expressions.whereClause);
    assertEquals(h, expressions.havingClause);
}
Also used : PColumn(org.apache.phoenix.schema.PColumn) CountAggregateFunction(org.apache.phoenix.expression.function.CountAggregateFunction) RoundDateExpression(org.apache.phoenix.expression.function.RoundDateExpression) Expression(org.apache.phoenix.expression.Expression) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) LiteralExpression(org.apache.phoenix.expression.LiteralExpression) RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Example 7 with RowKeyValueAccessor

use of org.apache.phoenix.schema.RowKeyValueAccessor in project phoenix by apache.

the class ExpressionCompiler method wrapGroupByExpression.

private Expression wrapGroupByExpression(Expression expression) {
    // column.
    if (aggregateFunction == null) {
        int index = groupBy.getExpressions().indexOf(expression);
        if (index >= 0) {
            isAggregate = true;
            RowKeyValueAccessor accessor = new RowKeyValueAccessor(groupBy.getKeyExpressions(), index);
            expression = new RowKeyColumnExpression(expression, accessor, groupBy.getKeyExpressions().get(index).getDataType());
        }
    }
    return expression;
}
Also used : RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression)

Example 8 with RowKeyValueAccessor

use of org.apache.phoenix.schema.RowKeyValueAccessor in project phoenix by apache.

the class WhereCompilerTest method testOrPKWithAndPKAndNotPK.

@Test
public void testOrPKWithAndPKAndNotPK() throws SQLException {
    String query = "select * from bugTable where ID = 'i1' or (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();
    Expression idExpression = new ColumnRef(plan.getTableRef(), plan.getTableRef().getTable().getColumnForColumnName("ID").getPosition()).newColumnExpression();
    Expression id = new RowKeyColumnExpression(idExpression, new RowKeyValueAccessor(plan.getTableRef().getTable().getPKColumns(), 0));
    Expression company = new KeyValueColumnExpression(plan.getTableRef().getTable().getColumnForColumnName("COMPANY"));
    // FilterList has no equals implementation
    assertTrue(filter instanceof FilterList);
    FilterList filterList = (FilterList) filter;
    assertEquals(FilterList.Operator.MUST_PASS_ALL, filterList.getOperator());
    assertEquals(Arrays.asList(new SkipScanFilter(ImmutableList.of(Arrays.asList(pointRange("i1"), pointRange("i2"))), SchemaUtil.VAR_BINARY_SCHEMA), singleKVFilter(or(constantComparison(CompareOp.EQUAL, id, "i1"), and(constantComparison(CompareOp.EQUAL, id, "i2"), constantComparison(CompareOp.EQUAL, company, "c3"))))), filterList.getFilters());
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) RowKeyValueAccessor(org.apache.phoenix.schema.RowKeyValueAccessor) FilterList(org.apache.hadoop.hbase.filter.FilterList) RowKeyColumnExpression(org.apache.phoenix.expression.RowKeyColumnExpression) 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) KeyValueColumnExpression(org.apache.phoenix.expression.KeyValueColumnExpression) PhoenixPreparedStatement(org.apache.phoenix.jdbc.PhoenixPreparedStatement) SkipScanFilter(org.apache.phoenix.filter.SkipScanFilter) Test(org.junit.Test) BaseConnectionlessQueryTest(org.apache.phoenix.query.BaseConnectionlessQueryTest)

Aggregations

RowKeyValueAccessor (org.apache.phoenix.schema.RowKeyValueAccessor)8 RowKeyColumnExpression (org.apache.phoenix.expression.RowKeyColumnExpression)7 LiteralExpression (org.apache.phoenix.expression.LiteralExpression)4 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)4 Test (org.junit.Test)4 Scan (org.apache.hadoop.hbase.client.Scan)3 Filter (org.apache.hadoop.hbase.filter.Filter)3 Expression (org.apache.phoenix.expression.Expression)3 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)3 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)3 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)3 PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)3 PColumn (org.apache.phoenix.schema.PColumn)3 TestUtil.multiEncodedKVFilter (org.apache.phoenix.util.TestUtil.multiEncodedKVFilter)3 TestUtil.singleKVFilter (org.apache.phoenix.util.TestUtil.singleKVFilter)3 KeyValueColumnExpression (org.apache.phoenix.expression.KeyValueColumnExpression)2 SubstrFunction (org.apache.phoenix.expression.function.SubstrFunction)2 SQLFeatureNotSupportedException (java.sql.SQLFeatureNotSupportedException)1 FilterList (org.apache.hadoop.hbase.filter.FilterList)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1