use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class MultipleInputNodeCreationProcessorTest method createChainableStream.
private void createChainableStream(TableTestUtil util) {
DataStreamSource<Integer> dataStream = util.getStreamEnv().fromSource(new MockSource(Boundedness.BOUNDED, 1), WatermarkStrategy.noWatermarks(), "chainableStream");
TableTestUtil.createTemporaryView(util.tableEnv(), "chainableStream", dataStream, scala.Option.apply(new Expression[] { ApiExpressionUtils.unresolvedRef("a") }), scala.Option.empty(), scala.Option.empty());
}
use of org.apache.flink.table.expressions.Expression 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());
}
use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class OperationTreeBuilder method map.
public QueryOperation map(Expression mapFunction, QueryOperation child) {
Expression resolvedMapFunction = mapFunction.accept(lookupResolver);
if (!isFunctionOfKind(resolvedMapFunction, FunctionKind.SCALAR)) {
throw new ValidationException("Only a scalar function can be used in the map operator.");
}
Expression expandedFields = unresolvedCall(BuiltInFunctionDefinitions.FLATTEN, resolvedMapFunction);
return project(Collections.singletonList(expandedFields), child, false);
}
use of org.apache.flink.table.expressions.Expression 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);
}
use of org.apache.flink.table.expressions.Expression in project flink by apache.
the class OperationTreeBuilder method renameColumns.
public QueryOperation renameColumns(List<Expression> aliases, QueryOperation child) {
ExpressionResolver resolver = getResolver(child);
final List<String> inputFieldNames = child.getResolvedSchema().getColumnNames();
List<Expression> validateAliases = ColumnOperationUtils.renameColumns(inputFieldNames, resolver.resolveExpanding(aliases));
return project(validateAliases, child, false);
}
Aggregations