use of org.apache.flink.table.planner.plan.nodes.calcite.LogicalWatermarkAssigner in project flink by apache.
the class ProjectWatermarkAssignerTransposeRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
LogicalProject project = call.rel(0);
LogicalWatermarkAssigner watermarkAssigner = call.rel(1);
NestedSchema usedFieldInProjectIncludingRowTimeFields = getUsedFieldsInTopLevelProjectAndWatermarkAssigner(project, watermarkAssigner);
return usedFieldInProjectIncludingRowTimeFields.columns().size() != watermarkAssigner.getRowType().getFieldCount();
}
use of org.apache.flink.table.planner.plan.nodes.calcite.LogicalWatermarkAssigner in project flink by apache.
the class ProjectWatermarkAssignerTransposeRule method onMatch.
@Override
public void onMatch(RelOptRuleCall call) {
LogicalProject project = call.rel(0);
LogicalWatermarkAssigner watermarkAssigner = call.rel(1);
// NOTES: DON'T use the nestedSchema datatype to build the transposed project.
NestedSchema nestedSchema = getUsedFieldsInTopLevelProjectAndWatermarkAssigner(project, watermarkAssigner);
FlinkRelBuilder builder = (FlinkRelBuilder) call.builder().push(watermarkAssigner.getInput());
List<RexInputRef> transposedProjects = new LinkedList<>();
List<String> usedNames = new LinkedList<>();
// add the used column RexInputRef and names into list
for (NestedColumn column : nestedSchema.columns().values()) {
// mark by hand
column.setIndexOfLeafInNewSchema(transposedProjects.size());
column.markLeaf();
usedNames.add(column.name());
transposedProjects.add(builder.field(column.indexInOriginSchema()));
}
// get the rowtime field index in the transposed project
String rowTimeName = watermarkAssigner.getRowType().getFieldNames().get(watermarkAssigner.rowtimeFieldIndex());
int indexOfRowTimeInTransposedProject;
if (nestedSchema.columns().get(rowTimeName) == null) {
// push the RexInputRef of the rowtime into the list
int rowTimeIndexInInput = watermarkAssigner.rowtimeFieldIndex();
indexOfRowTimeInTransposedProject = transposedProjects.size();
transposedProjects.add(builder.field(rowTimeIndexInInput));
usedNames.add(rowTimeName);
} else {
// find rowtime ref in the list and mark the location
indexOfRowTimeInTransposedProject = nestedSchema.columns().get(rowTimeName).indexOfLeafInNewSchema();
}
// the rowtime column has no rowtime indicator
builder.project(transposedProjects, usedNames);
// rewrite the top level field reference
RexNode newWatermarkExpr = watermarkAssigner.watermarkExpr().accept(new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef inputRef) {
String fieldName = watermarkAssigner.getRowType().getFieldNames().get(inputRef.getIndex());
return builder.field(nestedSchema.columns().get(fieldName).indexOfLeafInNewSchema());
}
});
builder.watermark(indexOfRowTimeInTransposedProject, newWatermarkExpr);
List<RexNode> newProjects = NestedProjectionUtil.rewrite(project.getProjects(), nestedSchema, call.builder().getRexBuilder());
RelNode newProject = builder.project(newProjects, project.getRowType().getFieldNames()).build();
call.transformTo(newProject);
}
Aggregations