use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class HavingCompilerTest method testAggFuncInHaving.
@Test
public void testAggFuncInHaving() throws SQLException {
String query = "select count(1) from atable group by a_string having count(a_string) >= 1";
List<Object> binds = Collections.emptyList();
Expressions expressions = compileStatement(query, binds);
Expression h = constantComparison(CompareOp.GREATER_OR_EQUAL, new CountAggregateFunction(Arrays.asList(A_STRING)), 1L);
assertNull(expressions.whereClause);
assertEquals(h, expressions.havingClause);
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class ExternalSqlTypeIdFunctionTest method testClone.
@Test
public void testClone() throws SQLException {
Expression inputArg = LiteralExpression.newConstant(PIntegerArray.INSTANCE.getSqlType(), PInteger.INSTANCE);
List<Expression> args = Lists.newArrayList(inputArg);
ExternalSqlTypeIdFunction externalIdFunction = new ExternalSqlTypeIdFunction(args);
ScalarFunction clone = externalIdFunction.clone(args);
assertEquals(externalIdFunction, clone);
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public Expression visitLeave(NotParseNode node, List<Expression> children) throws SQLException {
ParseNode childNode = node.getChildren().get(0);
Expression child = children.get(0);
if (!PBoolean.INSTANCE.isCoercibleTo(child.getDataType())) {
throw TypeMismatchException.newException(PBoolean.INSTANCE, child.getDataType(), node.toString());
}
if (childNode instanceof BindParseNode) {
// TODO: valid/possibe?
context.getBindManager().addParamMetaData((BindParseNode) childNode, child);
}
return wrapGroupByExpression(NotExpression.create(child, context.getTempPtr()));
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class ExpressionCompiler method visit.
@Override
public Expression visit(ColumnParseNode node) throws SQLException {
ColumnRef ref = resolveColumn(node);
TableRef tableRef = ref.getTableRef();
ImmutableBytesWritable ptr = context.getTempPtr();
PColumn column = ref.getColumn();
// query would become degenerate.
if (!resolveViewConstants && IndexUtil.getViewConstantValue(column, ptr)) {
return LiteralExpression.newConstant(column.getDataType().toObject(ptr), column.getDataType());
}
if (tableRef.equals(context.getCurrentTable()) && !SchemaUtil.isPKColumn(column)) {
// project only kv columns
addColumn(column);
}
Expression expression = ref.newColumnExpression(node.isTableNameCaseSensitive(), node.isCaseSensitive());
Expression wrappedExpression = wrapGroupByExpression(expression);
// This catches cases like this: SELECT sum(a_integer) + a_integer FROM atable GROUP BY a_string
if (isAggregate && aggregateFunction == null && wrappedExpression == expression) {
throwNonAggExpressionInAggException(expression.toString());
}
return wrappedExpression;
}
use of org.apache.phoenix.expression.Expression in project phoenix by apache.
the class ExpressionCompiler method visitLeave.
@Override
public Expression visitLeave(ComparisonParseNode node, List<Expression> children) throws SQLException {
ParseNode lhsNode = node.getChildren().get(0);
ParseNode rhsNode = node.getChildren().get(1);
Expression lhsExpr = children.get(0);
Expression rhsExpr = children.get(1);
CompareOp op = node.getFilterOp();
if (lhsNode instanceof RowValueConstructorParseNode && rhsNode instanceof RowValueConstructorParseNode) {
int i = 0;
for (; i < Math.min(lhsExpr.getChildren().size(), rhsExpr.getChildren().size()); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), rhsNode.getChildren().get(i), lhsExpr.getChildren().get(i), rhsExpr.getChildren().get(i));
}
for (; i < lhsExpr.getChildren().size(); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), null, lhsExpr.getChildren().get(i), null);
}
for (; i < rhsExpr.getChildren().size(); i++) {
addBindParamMetaData(null, rhsNode.getChildren().get(i), null, rhsExpr.getChildren().get(i));
}
} else if (lhsExpr instanceof RowValueConstructorExpression) {
addBindParamMetaData(lhsNode.getChildren().get(0), rhsNode, lhsExpr.getChildren().get(0), rhsExpr);
for (int i = 1; i < lhsExpr.getChildren().size(); i++) {
addBindParamMetaData(lhsNode.getChildren().get(i), null, lhsExpr.getChildren().get(i), null);
}
} else if (rhsExpr instanceof RowValueConstructorExpression) {
addBindParamMetaData(lhsNode, rhsNode.getChildren().get(0), lhsExpr, rhsExpr.getChildren().get(0));
for (int i = 1; i < rhsExpr.getChildren().size(); i++) {
addBindParamMetaData(null, rhsNode.getChildren().get(i), null, rhsExpr.getChildren().get(i));
}
} else {
addBindParamMetaData(lhsNode, rhsNode, lhsExpr, rhsExpr);
}
return wrapGroupByExpression(ComparisonExpression.create(op, children, context.getTempPtr(), context.getCurrentTable().getTable().rowKeyOrderOptimizable()));
}
Aggregations