Search in sources :

Example 1 with ExpressionResolver

use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.

the class OperationTreeBuilder method filter.

public QueryOperation filter(Expression condition, QueryOperation child) {
    ExpressionResolver resolver = getResolver(child);
    ResolvedExpression resolvedExpression = resolveSingleExpression(condition, resolver);
    DataType conditionType = resolvedExpression.getOutputDataType();
    if (!conditionType.getLogicalType().is(BOOLEAN)) {
        throw new ValidationException("Filter operator requires a boolean expression as input," + " but $condition is of type " + conditionType);
    }
    return new FilterQueryOperation(resolvedExpression, child);
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) DataType(org.apache.flink.table.types.DataType) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) SqlExpressionResolver(org.apache.flink.table.expressions.resolver.SqlExpressionResolver) FilterQueryOperation(org.apache.flink.table.operations.FilterQueryOperation)

Example 2 with ExpressionResolver

use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.

the class OperationTreeBuilder method join.

public QueryOperation join(QueryOperation left, QueryOperation right, JoinType joinType, Optional<Expression> condition, boolean correlated) {
    ExpressionResolver resolver = getResolver(left, right);
    Optional<ResolvedExpression> resolvedCondition = condition.map(expr -> resolveSingleExpression(expr, resolver));
    return joinOperationFactory.create(left, right, joinType, resolvedCondition.orElse(valueLiteral(true)), correlated);
}
Also used : ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) SqlExpressionResolver(org.apache.flink.table.expressions.resolver.SqlExpressionResolver)

Example 3 with ExpressionResolver

use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.

the class OperationTreeBuilder method windowTableAggregate.

public QueryOperation windowTableAggregate(List<Expression> groupingExpressions, GroupWindow window, List<Expression> windowProperties, Expression tableAggFunction, QueryOperation child) {
    // Step1: add a default name to the call in the grouping expressions, e.g., groupBy(a % 5)
    // to
    // groupBy(a % 5 as TMP_0). We need a name for every column so that to perform alias for the
    // table aggregate function in Step4.
    List<Expression> newGroupingExpressions = addAliasToTheCallInAggregate(child.getResolvedSchema().getColumnNames(), groupingExpressions);
    // Step2: resolve expressions, including grouping, aggregates and window properties.
    ExpressionResolver resolver = getAggResolver(child, groupingExpressions);
    ResolvedGroupWindow resolvedWindow = aggregateOperationFactory.createResolvedWindow(window, resolver);
    ExpressionResolver resolverWithWindowReferences = getResolverBuilder(child).withLocalReferences(localRef(resolvedWindow.getAlias(), resolvedWindow.getTimeAttribute().getOutputDataType())).build();
    List<ResolvedExpression> convertedGroupings = resolverWithWindowReferences.resolve(newGroupingExpressions);
    List<ResolvedExpression> convertedAggregates = resolverWithWindowReferences.resolve(Collections.singletonList(tableAggFunction));
    List<ResolvedExpression> convertedProperties = resolverWithWindowReferences.resolve(windowProperties);
    Tuple2<ResolvedExpression, List<String>> resolvedFunctionAndAlias = aggregateOperationFactory.extractTableAggFunctionAndAliases(convertedAggregates.get(0));
    // Step3: create window table agg operation
    QueryOperation tableAggOperation = aggregateOperationFactory.createWindowAggregate(convertedGroupings, Collections.singletonList(resolvedFunctionAndAlias.f0), convertedProperties, resolvedWindow, child);
    // window attribute.
    return aliasBackwardFields(tableAggOperation, resolvedFunctionAndAlias.f1, groupingExpressions.size());
}
Also used : ResolvedGroupWindow(org.apache.flink.table.operations.WindowAggregateQueryOperation.ResolvedGroupWindow) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) List(java.util.List) ArrayList(java.util.ArrayList) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) SqlExpressionResolver(org.apache.flink.table.expressions.resolver.SqlExpressionResolver) ValuesQueryOperation(org.apache.flink.table.operations.ValuesQueryOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) DistinctQueryOperation(org.apache.flink.table.operations.DistinctQueryOperation) FilterQueryOperation(org.apache.flink.table.operations.FilterQueryOperation)

Example 4 with ExpressionResolver

use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.

the class OperationTreeBuilder method windowAggregate.

public QueryOperation windowAggregate(List<Expression> groupingExpressions, GroupWindow window, List<Expression> windowProperties, List<Expression> aggregates, QueryOperation child) {
    ExpressionResolver resolver = getAggResolver(child, groupingExpressions);
    ResolvedGroupWindow resolvedWindow = aggregateOperationFactory.createResolvedWindow(window, resolver);
    ExpressionResolver resolverWithWindowReferences = getResolverBuilder(child).withLocalReferences(localRef(resolvedWindow.getAlias(), resolvedWindow.getTimeAttribute().getOutputDataType())).build();
    List<ResolvedExpression> convertedGroupings = resolverWithWindowReferences.resolve(groupingExpressions);
    List<ResolvedExpression> convertedAggregates = resolverWithWindowReferences.resolve(aggregates);
    List<ResolvedExpression> convertedProperties = resolverWithWindowReferences.resolve(windowProperties);
    return aggregateOperationFactory.createWindowAggregate(convertedGroupings, convertedAggregates, convertedProperties, resolvedWindow, child);
}
Also used : ResolvedGroupWindow(org.apache.flink.table.operations.WindowAggregateQueryOperation.ResolvedGroupWindow) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) SqlExpressionResolver(org.apache.flink.table.expressions.resolver.SqlExpressionResolver)

Example 5 with ExpressionResolver

use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.

the class OperationTreeBuilder method dropColumns.

public QueryOperation dropColumns(List<Expression> fieldLists, QueryOperation child) {
    ExpressionResolver resolver = getResolver(child);
    List<String> inputFieldNames = child.getResolvedSchema().getColumnNames();
    List<Expression> finalFields = ColumnOperationUtils.dropFields(inputFieldNames, resolver.resolveExpanding(fieldLists));
    return project(finalFields, child, false);
}
Also used : ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) Expression(org.apache.flink.table.expressions.Expression) UnresolvedCallExpression(org.apache.flink.table.expressions.UnresolvedCallExpression) ExpressionResolver(org.apache.flink.table.expressions.resolver.ExpressionResolver) SqlExpressionResolver(org.apache.flink.table.expressions.resolver.SqlExpressionResolver)

Aggregations

ResolvedExpression (org.apache.flink.table.expressions.ResolvedExpression)15 ExpressionResolver (org.apache.flink.table.expressions.resolver.ExpressionResolver)15 SqlExpressionResolver (org.apache.flink.table.expressions.resolver.SqlExpressionResolver)14 Expression (org.apache.flink.table.expressions.Expression)8 UnresolvedCallExpression (org.apache.flink.table.expressions.UnresolvedCallExpression)7 FilterQueryOperation (org.apache.flink.table.operations.FilterQueryOperation)7 ArrayList (java.util.ArrayList)6 DistinctQueryOperation (org.apache.flink.table.operations.DistinctQueryOperation)6 QueryOperation (org.apache.flink.table.operations.QueryOperation)6 ValuesQueryOperation (org.apache.flink.table.operations.ValuesQueryOperation)6 List (java.util.List)3 ResolvedGroupWindow (org.apache.flink.table.operations.WindowAggregateQueryOperation.ResolvedGroupWindow)3 ValidationException (org.apache.flink.table.api.ValidationException)2 HashSet (java.util.HashSet)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 TimeZone (java.util.TimeZone)1 Collectors (java.util.stream.Collectors)1 RexBuilder (org.apache.calcite.rex.RexBuilder)1 RexNode (org.apache.calcite.rex.RexNode)1