use of org.apache.flink.table.expressions.UnresolvedCallExpression in project flink by apache.
the class DeclarativeExpressionResolver method defaultMethod.
@Override
protected ResolvedExpression defaultMethod(Expression expression) {
if (expression instanceof UnresolvedReferenceExpression) {
UnresolvedReferenceExpression expr = (UnresolvedReferenceExpression) expression;
String name = expr.getName();
int localIndex = ArrayUtils.indexOf(function.aggBufferAttributes(), expr);
if (localIndex == -1) {
// case, the input is aggregate buffers which sent by local aggregate.
if (isMerge) {
return toMergeInputExpr(name, ArrayUtils.indexOf(function.mergeOperands(), expr));
} else {
return toAccInputExpr(name, ArrayUtils.indexOf(function.operands(), expr));
}
} else {
return toAggBufferExpr(name, localIndex);
}
} else if (expression instanceof UnresolvedCallExpression) {
UnresolvedCallExpression unresolvedCall = (UnresolvedCallExpression) expression;
return resolver.resolve(ApiExpressionUtils.unresolvedCall(unresolvedCall.getFunctionDefinition(), unresolvedCall.getChildren().stream().map(c -> c.accept(DeclarativeExpressionResolver.this)).collect(Collectors.toList())));
} else if (expression instanceof ResolvedExpression) {
return (ResolvedExpression) expression;
} else {
return resolver.resolve(expression);
}
}
use of org.apache.flink.table.expressions.UnresolvedCallExpression in project flink by apache.
the class OperationTreeBuilder method addAliasToTheCallInAggregate.
/**
* Add a default name to the call in the grouping expressions, e.g., groupBy(a % 5) to groupBy(a
* % 5 as TMP_0) or make aggregate a named aggregate.
*/
private List<Expression> addAliasToTheCallInAggregate(List<String> inputFieldNames, List<Expression> expressions) {
int attrNameCntr = 0;
Set<String> usedFieldNames = new HashSet<>(inputFieldNames);
List<Expression> result = new ArrayList<>();
for (Expression groupingExpression : expressions) {
if (groupingExpression instanceof UnresolvedCallExpression && !ApiExpressionUtils.isFunction(groupingExpression, BuiltInFunctionDefinitions.AS)) {
String tempName = getUniqueName("TMP_" + attrNameCntr, usedFieldNames);
attrNameCntr += 1;
usedFieldNames.add(tempName);
result.add(unresolvedCall(BuiltInFunctionDefinitions.AS, groupingExpression, valueLiteral(tempName)));
} else {
result.add(groupingExpression);
}
}
return result;
}
Aggregations