use of org.apache.flink.api.dag.Transformation in project flink by apache.
the class StreamExecWindowRank method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
// validate rank type
switch(rankType) {
case ROW_NUMBER:
break;
case RANK:
throw new TableException("RANK() function is not supported on Window TopN currently, only ROW_NUMBER() is supported.");
case DENSE_RANK:
throw new TableException("DENSE_RANK() function is not supported on Window TopN currently, only ROW_NUMBER() is supported.");
default:
throw new TableException(String.format("%s() function is not supported on Window TopN currently, only ROW_NUMBER() is supported.", rankType));
}
// validate window strategy
if (!windowing.isRowtime()) {
throw new TableException("Processing time Window TopN is not supported yet.");
}
int windowEndIndex;
if (windowing instanceof WindowAttachedWindowingStrategy) {
windowEndIndex = ((WindowAttachedWindowingStrategy) windowing).getWindowEnd();
} else {
throw new UnsupportedOperationException(windowing.getClass().getName() + " is not supported yet.");
}
ExecEdge inputEdge = getInputEdges().get(0);
RowType inputType = (RowType) inputEdge.getOutputType();
// validate rank range
ConstantRankRange constantRankRange;
if (rankRange instanceof ConstantRankRange) {
constantRankRange = (ConstantRankRange) rankRange;
} else {
throw new TableException(String.format("Rank strategy %s is not supported on window rank currently.", rankRange.toString(inputType.getFieldNames())));
}
Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
InternalTypeInfo<RowData> inputRowTypeInfo = InternalTypeInfo.of(inputType);
int[] sortFields = sortSpec.getFieldIndices();
RowDataKeySelector sortKeySelector = KeySelectorUtil.getRowDataSelector(sortFields, inputRowTypeInfo);
SortSpec.SortSpecBuilder builder = SortSpec.builder();
IntStream.range(0, sortFields.length).forEach(idx -> builder.addField(idx, sortSpec.getFieldSpec(idx).getIsAscendingOrder(), sortSpec.getFieldSpec(idx).getNullIsLast()));
SortSpec sortSpecInSortKey = builder.build();
ZoneId shiftTimeZone = TimeWindowUtil.getShiftTimeZone(windowing.getTimeAttributeType(), config.getLocalTimeZone());
GeneratedRecordComparator sortKeyComparator = ComparatorCodeGenerator.gen(config.getTableConfig(), "StreamExecSortComparator", RowType.of(sortSpec.getFieldTypes(inputType)), sortSpecInSortKey);
RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(partitionSpec.getFieldIndices(), inputRowTypeInfo);
OneInputStreamOperator<RowData, RowData> operator = WindowRankOperatorBuilder.builder().inputSerializer(new RowDataSerializer(inputType)).shiftTimeZone(shiftTimeZone).keySerializer((PagedTypeSerializer<RowData>) selector.getProducedType().toSerializer()).sortKeySelector(sortKeySelector).sortKeyComparator(sortKeyComparator).outputRankNumber(outputRankNumber).rankStart(constantRankRange.getRankStart()).rankEnd(constantRankRange.getRankEnd()).windowEndIndex(windowEndIndex).build();
OneInputTransformation<RowData, RowData> transform = ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(WINDOW_RANK_TRANSFORMATION, config), SimpleOperatorFactory.of(operator), InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism(), WINDOW_RANK_MEMORY_RATIO);
// set KeyType and Selector for state
transform.setStateKeySelector(selector);
transform.setStateKeyType(selector.getProducedType());
return transform;
}
use of org.apache.flink.api.dag.Transformation in project flink by apache.
the class StreamExecIntervalJoin method translateToPlanInternal.
@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
ExecEdge leftInputEdge = getInputEdges().get(0);
ExecEdge rightInputEdge = getInputEdges().get(1);
RowType leftRowType = (RowType) leftInputEdge.getOutputType();
RowType rightRowType = (RowType) rightInputEdge.getOutputType();
Transformation<RowData> leftInputTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
Transformation<RowData> rightInputTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
RowType returnType = (RowType) getOutputType();
InternalTypeInfo<RowData> returnTypeInfo = InternalTypeInfo.of(returnType);
JoinSpec joinSpec = intervalJoinSpec.getJoinSpec();
IntervalJoinSpec.WindowBounds windowBounds = intervalJoinSpec.getWindowBounds();
switch(joinSpec.getJoinType()) {
case INNER:
case LEFT:
case RIGHT:
case FULL:
long relativeWindowSize = windowBounds.getLeftUpperBound() - windowBounds.getLeftLowerBound();
if (relativeWindowSize < 0) {
LOGGER.warn("The relative time interval size " + relativeWindowSize + "is negative, please check the join conditions.");
return createNegativeWindowSizeJoin(joinSpec, leftInputTransform, rightInputTransform, leftRowType.getFieldCount(), rightRowType.getFieldCount(), returnTypeInfo, config);
} else {
GeneratedJoinCondition joinCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftRowType, rightRowType);
IntervalJoinFunction joinFunction = new IntervalJoinFunction(joinCondition, returnTypeInfo, joinSpec.getFilterNulls());
TwoInputTransformation<RowData, RowData, RowData> transform;
if (windowBounds.isEventTime()) {
transform = createRowTimeJoin(leftInputTransform, rightInputTransform, returnTypeInfo, joinFunction, joinSpec, windowBounds, config);
} else {
transform = createProcTimeJoin(leftInputTransform, rightInputTransform, returnTypeInfo, joinFunction, joinSpec, windowBounds, config);
}
if (inputsContainSingleton()) {
transform.setParallelism(1);
transform.setMaxParallelism(1);
}
// set KeyType and Selector for state
RowDataKeySelector leftSelect = KeySelectorUtil.getRowDataSelector(joinSpec.getLeftKeys(), InternalTypeInfo.of(leftRowType));
RowDataKeySelector rightSelect = KeySelectorUtil.getRowDataSelector(joinSpec.getRightKeys(), InternalTypeInfo.of(rightRowType));
transform.setStateKeySelectors(leftSelect, rightSelect);
transform.setStateKeyType(leftSelect.getProducedType());
return transform;
}
default:
throw new TableException("Interval Join: " + joinSpec.getJoinType() + " Join between stream " + "and stream is not supported yet.\nplease re-check " + "interval join statement according to description above.");
}
}
use of org.apache.flink.api.dag.Transformation in project flink by apache.
the class StreamExecJoin method translateToPlanInternal.
@Override
@SuppressWarnings("unchecked")
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final ExecEdge leftInputEdge = getInputEdges().get(0);
final ExecEdge rightInputEdge = getInputEdges().get(1);
final Transformation<RowData> leftTransform = (Transformation<RowData>) leftInputEdge.translateToPlan(planner);
final Transformation<RowData> rightTransform = (Transformation<RowData>) rightInputEdge.translateToPlan(planner);
final RowType leftType = (RowType) leftInputEdge.getOutputType();
final RowType rightType = (RowType) rightInputEdge.getOutputType();
JoinUtil.validateJoinSpec(joinSpec, leftType, rightType, true);
final int[] leftJoinKey = joinSpec.getLeftKeys();
final int[] rightJoinKey = joinSpec.getRightKeys();
final InternalTypeInfo<RowData> leftTypeInfo = InternalTypeInfo.of(leftType);
final JoinInputSideSpec leftInputSpec = JoinUtil.analyzeJoinInput(leftTypeInfo, leftJoinKey, leftUniqueKeys);
final InternalTypeInfo<RowData> rightTypeInfo = InternalTypeInfo.of(rightType);
final JoinInputSideSpec rightInputSpec = JoinUtil.analyzeJoinInput(rightTypeInfo, rightJoinKey, rightUniqueKeys);
GeneratedJoinCondition generatedCondition = JoinUtil.generateConditionFunction(config.getTableConfig(), joinSpec, leftType, rightType);
long minRetentionTime = config.getStateRetentionTime();
AbstractStreamingJoinOperator operator;
FlinkJoinType joinType = joinSpec.getJoinType();
if (joinType == FlinkJoinType.ANTI || joinType == FlinkJoinType.SEMI) {
operator = new StreamingSemiAntiJoinOperator(joinType == FlinkJoinType.ANTI, leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, joinSpec.getFilterNulls(), minRetentionTime);
} else {
boolean leftIsOuter = joinType == FlinkJoinType.LEFT || joinType == FlinkJoinType.FULL;
boolean rightIsOuter = joinType == FlinkJoinType.RIGHT || joinType == FlinkJoinType.FULL;
operator = new StreamingJoinOperator(leftTypeInfo, rightTypeInfo, generatedCondition, leftInputSpec, rightInputSpec, leftIsOuter, rightIsOuter, joinSpec.getFilterNulls(), minRetentionTime);
}
final RowType returnType = (RowType) getOutputType();
final TwoInputTransformation<RowData, RowData, RowData> transform = ExecNodeUtil.createTwoInputTransformation(leftTransform, rightTransform, createTransformationMeta(JOIN_TRANSFORMATION, config), operator, InternalTypeInfo.of(returnType), leftTransform.getParallelism());
// set KeyType and Selector for state
RowDataKeySelector leftSelect = KeySelectorUtil.getRowDataSelector(leftJoinKey, leftTypeInfo);
RowDataKeySelector rightSelect = KeySelectorUtil.getRowDataSelector(rightJoinKey, rightTypeInfo);
transform.setStateKeySelectors(leftSelect, rightSelect);
transform.setStateKeyType(leftSelect.getProducedType());
return transform;
}
use of org.apache.flink.api.dag.Transformation in project flink by apache.
the class StreamExecLocalGroupAggregate method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final ExecEdge inputEdge = getInputEdges().get(0);
final Transformation<RowData> inputTransform = (Transformation<RowData>) inputEdge.translateToPlan(planner);
final RowType inputRowType = (RowType) inputEdge.getOutputType();
final AggsHandlerCodeGenerator generator = new AggsHandlerCodeGenerator(new CodeGeneratorContext(config.getTableConfig()), planner.getRelBuilder(), JavaScalaConversionUtil.toScala(inputRowType.getChildren()), // the local aggregate result will be buffered, so need copy
true);
generator.needAccumulate().needMerge(0, true, null);
if (needRetraction) {
generator.needRetract();
}
final AggregateInfoList aggInfoList = AggregateUtil.transformToStreamAggregateInfoList(inputRowType, JavaScalaConversionUtil.toScala(Arrays.asList(aggCalls)), aggCallNeedRetractions, needRetraction, // isStateBackendDataViews
false, // needDistinctInfo
true);
final GeneratedAggsHandleFunction aggsHandler = generator.generateAggsHandler("GroupAggsHandler", aggInfoList);
final MiniBatchLocalGroupAggFunction aggFunction = new MiniBatchLocalGroupAggFunction(aggsHandler);
final RowDataKeySelector selector = KeySelectorUtil.getRowDataSelector(grouping, (InternalTypeInfo<RowData>) inputTransform.getOutputType());
final MapBundleOperator<RowData, RowData, RowData, RowData> operator = new MapBundleOperator<>(aggFunction, AggregateUtil.createMiniBatchTrigger(config), selector);
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(LOCAL_GROUP_AGGREGATE_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
}
use of org.apache.flink.api.dag.Transformation in project flink by apache.
the class StreamExecMiniBatchAssigner method translateToPlanInternal.
@SuppressWarnings("unchecked")
@Override
protected Transformation<RowData> translateToPlanInternal(PlannerBase planner, ExecNodeConfig config) {
final Transformation<RowData> inputTransform = (Transformation<RowData>) getInputEdges().get(0).translateToPlan(planner);
final OneInputStreamOperator<RowData, RowData> operator;
if (miniBatchInterval.getMode() == MiniBatchMode.ProcTime) {
operator = new ProcTimeMiniBatchAssignerOperator(miniBatchInterval.getInterval());
} else if (miniBatchInterval.getMode() == MiniBatchMode.RowTime) {
operator = new RowTimeMiniBatchAssginerOperator(miniBatchInterval.getInterval());
} else {
throw new TableException(String.format("MiniBatchAssigner shouldn't be in %s mode this is a bug, please file an issue.", miniBatchInterval.getMode()));
}
return ExecNodeUtil.createOneInputTransformation(inputTransform, createTransformationMeta(MINI_BATCH_ASSIGNER_TRANSFORMATION, config), operator, InternalTypeInfo.of(getOutputType()), inputTransform.getParallelism());
}
Aggregations