Search in sources :

Example 1 with UnresolvedCallExpression

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);
    }
}
Also used : UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) UnresolvedReferenceExpression(org.apache.flink.table.expressions.UnresolvedReferenceExpression) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression)

Example 2 with UnresolvedCallExpression

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;
}
Also used : UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Aggregations

ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)2 UnresolvedCallExpression (org.apache.flink.table.expressions.UnresolvedCallExpression)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Expression (org.apache.flink.table.expressions.Expression)1 UnresolvedReferenceExpression (org.apache.flink.table.expressions.UnresolvedReferenceExpression)1