use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.
the class OperationTreeBuilder method tableAggregate.
public QueryOperation tableAggregate(List<Expression> groupingExpressions, 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
ExpressionResolver resolver = getAggResolver(child, groupingExpressions);
List<ResolvedExpression> resolvedGroupings = resolver.resolve(newGroupingExpressions);
Tuple2<ResolvedExpression, List<String>> resolvedFunctionAndAlias = aggregateOperationFactory.extractTableAggFunctionAndAliases(resolveSingleExpression(tableAggFunction, resolver));
// Step3: create table agg operation
QueryOperation tableAggOperation = aggregateOperationFactory.createAggregate(resolvedGroupings, Collections.singletonList(resolvedFunctionAndAlias.f0), child);
// Step4: add a top project to alias the output fields of the table aggregate.
return aliasBackwardFields(tableAggOperation, resolvedFunctionAndAlias.f1, groupingExpressions.size());
}
use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.
the class OperationTreeBuilder method projectInternal.
private QueryOperation projectInternal(List<Expression> projectList, QueryOperation child, boolean explicitAlias, List<OverWindow> overWindows) {
ExpressionResolver resolver = getResolverBuilder(child).withOverWindows(overWindows).build();
List<ResolvedExpression> projections = resolver.resolve(projectList);
return projectionOperationFactory.create(projections, child, explicitAlias, resolver.postResolverFactory());
}
use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.
the class OperationTreeBuilder method sort.
public QueryOperation sort(List<Expression> fields, QueryOperation child) {
ExpressionResolver resolver = getResolver(child);
List<ResolvedExpression> resolvedFields = resolver.resolve(fields);
return sortOperationFactory.createSort(resolvedFields, child, resolver.postResolverFactory());
}
use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.
the class OperationTreeBuilder method aggregate.
public QueryOperation aggregate(List<Expression> groupingExpressions, List<Expression> aggregates, QueryOperation child) {
ExpressionResolver resolver = getAggResolver(child, groupingExpressions);
List<ResolvedExpression> resolvedGroupings = resolver.resolve(groupingExpressions);
List<ResolvedExpression> resolvedAggregates = resolver.resolve(aggregates);
return aggregateOperationFactory.createAggregate(resolvedGroupings, resolvedAggregates, child);
}
use of org.apache.flink.table.expressions.resolver.ExpressionResolver in project flink by apache.
the class FilterPushDownSpec method apply.
public static SupportsFilterPushDown.Result apply(List<RexNode> predicates, DynamicTableSource tableSource, SourceAbilityContext context) {
if (tableSource instanceof SupportsFilterPushDown) {
RexNodeToExpressionConverter converter = new RexNodeToExpressionConverter(new RexBuilder(FlinkTypeFactory.INSTANCE()), context.getSourceRowType().getFieldNames().toArray(new String[0]), context.getFunctionCatalog(), context.getCatalogManager(), TimeZone.getTimeZone(context.getTableConfig().getLocalTimeZone()));
List<Expression> filters = predicates.stream().map(p -> {
scala.Option<ResolvedExpression> expr = p.accept(converter);
if (expr.isDefined()) {
return expr.get();
} else {
throw new TableException(String.format("%s can not be converted to Expression, please make sure %s can accept %s.", p.toString(), tableSource.getClass().getSimpleName(), p.toString()));
}
}).collect(Collectors.toList());
ExpressionResolver resolver = ExpressionResolver.resolverFor(context.getTableConfig(), name -> Optional.empty(), context.getFunctionCatalog().asLookup(str -> {
throw new TableException("We should not need to lookup any expressions at this point");
}), context.getCatalogManager().getDataTypeFactory(), (sqlExpression, inputRowType, outputType) -> {
throw new TableException("SQL expression parsing is not supported at this location.");
}).build();
return ((SupportsFilterPushDown) tableSource).applyFilters(resolver.resolve(filters));
} else {
throw new TableException(String.format("%s does not support SupportsFilterPushDown.", tableSource.getClass().getName()));
}
}
Aggregations