use of org.apache.flink.table.expressions.ResolvedExpression 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.ResolvedExpression 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.ResolvedExpression 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.ResolvedExpression in project flink by apache.
the class AggregateOperationFactory method getValidatedTimeAttribute.
private FieldReferenceExpression getValidatedTimeAttribute(GroupWindow window, ExpressionResolver resolver) {
List<ResolvedExpression> timeFieldExprs = resolver.resolve(singletonList(window.getTimeField()));
if (timeFieldExprs.size() != 1) {
throw new ValidationException("A group window only supports a single time field column.");
}
Expression timeFieldExpr = timeFieldExprs.get(0);
if (!(timeFieldExpr instanceof FieldReferenceExpression)) {
throw new ValidationException("A group window expects a time attribute for grouping.");
}
FieldReferenceExpression timeField = (FieldReferenceExpression) timeFieldExpr;
final LogicalType timeFieldType = timeField.getOutputDataType().getLogicalType();
validateTimeAttributeType(timeFieldType);
return timeField;
}
use of org.apache.flink.table.expressions.ResolvedExpression in project flink by apache.
the class OverConvertRule method convert.
@Override
public Optional<RexNode> convert(CallExpression call, ConvertContext context) {
List<Expression> children = call.getChildren();
if (call.getFunctionDefinition() == BuiltInFunctionDefinitions.OVER) {
FlinkTypeFactory typeFactory = context.getTypeFactory();
Expression agg = children.get(0);
FunctionDefinition def = ((CallExpression) agg).getFunctionDefinition();
boolean isDistinct = BuiltInFunctionDefinitions.DISTINCT == def;
SqlAggFunction aggFunc = agg.accept(new SqlAggFunctionVisitor(context.getRelBuilder()));
RelDataType aggResultType = typeFactory.createFieldTypeFromLogicalType(fromDataTypeToLogicalType(((ResolvedExpression) agg).getOutputDataType()));
// assemble exprs by agg children
List<RexNode> aggExprs = agg.getChildren().stream().map(child -> {
if (isDistinct) {
return context.toRexNode(child.getChildren().get(0));
} else {
return context.toRexNode(child);
}
}).collect(Collectors.toList());
// assemble order by key
Expression orderKeyExpr = children.get(1);
Set<SqlKind> kinds = new HashSet<>();
RexNode collationRexNode = createCollation(context.toRexNode(orderKeyExpr), RelFieldCollation.Direction.ASCENDING, null, kinds);
ImmutableList<RexFieldCollation> orderKey = ImmutableList.of(new RexFieldCollation(collationRexNode, kinds));
// assemble partition by keys
List<RexNode> partitionKeys = children.subList(4, children.size()).stream().map(context::toRexNode).collect(Collectors.toList());
// assemble bounds
Expression preceding = children.get(2);
boolean isPhysical = fromDataTypeToLogicalType(((ResolvedExpression) preceding).getOutputDataType()).is(LogicalTypeRoot.BIGINT);
Expression following = children.get(3);
RexWindowBound lowerBound = createBound(context, preceding, SqlKind.PRECEDING);
RexWindowBound upperBound = createBound(context, following, SqlKind.FOLLOWING);
// build RexOver
return Optional.of(context.getRelBuilder().getRexBuilder().makeOver(aggResultType, aggFunc, aggExprs, partitionKeys, orderKey, lowerBound, upperBound, isPhysical, true, false, isDistinct));
}
return Optional.empty();
}
Aggregations