use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project flink by apache.
the class WatermarkAssignerChangelogNormalizeTransposeRule method buildMapping.
private Mappings.TargetMapping buildMapping(RexProgram program) {
final Map<Integer, Integer> mapInToOutPos = new HashMap<>();
final List<RexLocalRef> projects = program.getProjectList();
for (int idx = 0; idx < projects.size(); idx++) {
RexNode rexNode = program.expandLocalRef(projects.get(idx));
if (rexNode instanceof RexInputRef) {
mapInToOutPos.put(((RexInputRef) rexNode).getIndex(), idx);
}
}
return Mappings.target(mapInToOutPos, program.getInputRowType().getFieldCount(), program.getOutputRowType().getFieldCount());
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project flink by apache.
the class PythonCorrelateSplitRule method createTopCalc.
private FlinkLogicalCalc createTopCalc(int primitiveLeftFieldCount, RexBuilder rexBuilder, ArrayBuffer<RexNode> extractedRexNodes, RelDataType calcRowType, FlinkLogicalCorrelate newCorrelate) {
RexProgram rexProgram = new RexProgramBuilder(newCorrelate.getRowType(), rexBuilder).getProgram();
int offset = extractedRexNodes.size() + primitiveLeftFieldCount;
// extract correlate output RexNode.
List<RexNode> newTopCalcProjects = rexProgram.getExprList().stream().filter(x -> x instanceof RexInputRef).filter(x -> {
int index = ((RexInputRef) x).getIndex();
return index < primitiveLeftFieldCount || index >= offset;
}).collect(Collectors.toList());
return new FlinkLogicalCalc(newCorrelate.getCluster(), newCorrelate.getTraitSet(), newCorrelate, RexProgram.create(newCorrelate.getRowType(), newTopCalcProjects, null, calcRowType, rexBuilder));
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project flink by apache.
the class FlinkSemiAntiJoinProjectTransposeRule method matches.
@Override
public boolean matches(RelOptRuleCall call) {
LogicalJoin join = call.rel(0);
LogicalProject project = call.rel(1);
// only accept SEMI/ANTI join
JoinRelType joinType = join.getJoinType();
if (joinType != JoinRelType.SEMI && joinType != JoinRelType.ANTI) {
return false;
}
// all expressions in Project should be RexInputRef
for (RexNode p : project.getProjects()) {
if (!(p instanceof RexInputRef)) {
return false;
}
}
return true;
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project flink by apache.
the class RelTimeIndicatorConverter method createCalcToMaterializeTimeIndicators.
private RelNode createCalcToMaterializeTimeIndicators(RelNode input, Set<Integer> refIndices) {
// create new calc
List<RexNode> projects = input.getRowType().getFieldList().stream().map(field -> {
RexNode project = new RexInputRef(field.getIndex(), field.getType());
if (refIndices.contains(field.getIndex())) {
project = materializeTimeIndicators(project);
}
return project;
}).collect(Collectors.toList());
RexProgram newProgram = RexProgram.create(input.getRowType(), projects, null, input.getRowType().getFieldNames(), rexBuilder);
return FlinkLogicalCalc.create(input, newProgram);
}
use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.rex.RexInputRef in project flink by apache.
the class RelTimeIndicatorConverter method visitJoin.
private RelNode visitJoin(FlinkLogicalJoin join) {
RelNode newLeft = join.getLeft().accept(this);
RelNode newRight = join.getRight().accept(this);
int leftFieldCount = newLeft.getRowType().getFieldCount();
// temporal table join
if (TemporalJoinUtil.satisfyTemporalJoin(join, newLeft, newRight)) {
RelNode rewrittenTemporalJoin = join.copy(join.getTraitSet(), join.getCondition(), newLeft, newRight, join.getJoinType(), join.isSemiJoinDone());
// Materialize all of the time attributes from the right side of temporal join
Set<Integer> rightIndices = IntStream.range(0, newRight.getRowType().getFieldCount()).mapToObj(startIdx -> leftFieldCount + startIdx).collect(Collectors.toSet());
return createCalcToMaterializeTimeIndicators(rewrittenTemporalJoin, rightIndices);
} else {
if (JoinUtil.satisfyRegularJoin(join, newLeft, newRight)) {
// materialize time attribute fields of regular join's inputs
newLeft = materializeTimeIndicators(newLeft);
newRight = materializeTimeIndicators(newRight);
}
List<RelDataTypeField> leftRightFields = new ArrayList<>();
leftRightFields.addAll(newLeft.getRowType().getFieldList());
leftRightFields.addAll(newRight.getRowType().getFieldList());
RexNode newCondition = join.getCondition().accept(new RexShuttle() {
@Override
public RexNode visitInputRef(RexInputRef inputRef) {
if (isTimeIndicatorType(inputRef.getType())) {
return RexInputRef.of(inputRef.getIndex(), leftRightFields);
} else {
return super.visitInputRef(inputRef);
}
}
});
return FlinkLogicalJoin.create(newLeft, newRight, newCondition, join.getJoinType());
}
}
Aggregations