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);
}
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;
}
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());
}
Aggregations