Search in sources :

Example 1 with FlinkLogicalJoin

use of org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalJoin 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());
    }
}
Also used : WindowUtil.groupingContainsWindowStartEnd(org.apache.flink.table.planner.plan.utils.WindowUtil.groupingContainsWindowStartEnd) RexProgram(org.apache.calcite.rex.RexProgram) Tuple2(org.apache.flink.api.java.tuple.Tuple2) FlinkLogicalWindowAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowAggregate) LogicalTableModify(org.apache.calcite.rel.logical.LogicalTableModify) FlinkLogicalLegacySink(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalLegacySink) FlinkLogicalDistribution(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalDistribution) FlinkLogicalIntersect(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalIntersect) TemporalJoinUtil(org.apache.flink.table.planner.plan.utils.TemporalJoinUtil) RexPatternFieldRef(org.apache.calcite.rex.RexPatternFieldRef) RexNode(org.apache.calcite.rex.RexNode) Map(java.util.Map) FlinkLogicalSnapshot(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSnapshot) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) FlinkLogicalMinus(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalMinus) Predicate(java.util.function.Predicate) FlinkLogicalTableFunctionScan(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableFunctionScan) FlinkLogicalRank(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalRank) Set(java.util.Set) FlinkLogicalJoin(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalJoin) Preconditions(org.apache.flink.util.Preconditions) Collectors(java.util.stream.Collectors) FlinkLogicalValues(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalValues) RexInputRef(org.apache.calcite.rex.RexInputRef) List(java.util.List) FlinkTypeFactory.isTimeIndicatorType(org.apache.flink.table.planner.calcite.FlinkTypeFactory.isTimeIndicatorType) LogicalType(org.apache.flink.table.types.logical.LogicalType) SqlStdOperatorTable(org.apache.calcite.sql.fun.SqlStdOperatorTable) FlinkLogicalSink(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSink) RexLocalRef(org.apache.calcite.rex.RexLocalRef) ValidationException(org.apache.flink.table.api.ValidationException) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) FlinkTypeFactory.isRowtimeIndicatorType(org.apache.flink.table.planner.calcite.FlinkTypeFactory.isRowtimeIndicatorType) FlinkLogicalSort(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalSort) FlinkLogicalOverAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalOverAggregate) RexCall(org.apache.calcite.rex.RexCall) IntStream(java.util.stream.IntStream) TableScan(org.apache.calcite.rel.core.TableScan) LogicalCalc(org.apache.calcite.rel.logical.LogicalCalc) FlinkLogicalMatch(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalMatch) FlinkLogicalUnion(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalUnion) SetOp(org.apache.calcite.rel.core.SetOp) RelWindowProperties(org.apache.flink.table.planner.plan.trait.RelWindowProperties) RelOptUtil(org.apache.calcite.plan.RelOptUtil) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) MatchUtil.isFinalOnMatchTimeIndicator(org.apache.flink.table.planner.plan.utils.MatchUtil.isFinalOnMatchTimeIndicator) TimestampType(org.apache.flink.table.types.logical.TimestampType) Pair(org.apache.calcite.util.Pair) FlinkLogicalAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalAggregate) TimeIndicatorRelDataType(org.apache.flink.table.planner.plan.schema.TimeIndicatorRelDataType) SqlOperator(org.apache.calcite.sql.SqlOperator) SingleRel(org.apache.calcite.rel.SingleRel) RelCollations(org.apache.calcite.rel.RelCollations) RelDataType(org.apache.calcite.rel.type.RelDataType) SqlTypeName(org.apache.calcite.sql.type.SqlTypeName) FlinkRelMetadataQuery(org.apache.flink.table.planner.plan.metadata.FlinkRelMetadataQuery) RexBuilder(org.apache.calcite.rex.RexBuilder) FlinkTypeFactory.isProctimeIndicatorType(org.apache.flink.table.planner.calcite.FlinkTypeFactory.isProctimeIndicatorType) TableException(org.apache.flink.table.api.TableException) FlinkLogicalTableAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalTableAggregate) FlinkLogicalCalc(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCalc) FlinkLogicalWindowTableAggregate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWindowTableAggregate) FlinkLogicalExpand(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalExpand) RelNode(org.apache.calcite.rel.RelNode) Aggregate(org.apache.calcite.rel.core.Aggregate) JoinUtil(org.apache.flink.table.planner.plan.utils.JoinUtil) RelHomogeneousShuttle(org.apache.calcite.rel.RelHomogeneousShuttle) RexProgramBuilder(org.apache.calcite.rex.RexProgramBuilder) FlinkSqlOperatorTable(org.apache.flink.table.planner.functions.sql.FlinkSqlOperatorTable) FlinkLogicalWatermarkAssigner(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalWatermarkAssigner) AggregateCall(org.apache.calcite.rel.core.AggregateCall) RexShuttle(org.apache.calcite.rex.RexShuttle) FlinkLogicalCorrelate(org.apache.flink.table.planner.plan.nodes.logical.FlinkLogicalCorrelate) Collections(java.util.Collections) RelDataTypeField(org.apache.calcite.rel.type.RelDataTypeField) RexShuttle(org.apache.calcite.rex.RexShuttle) RelNode(org.apache.calcite.rel.RelNode) ArrayList(java.util.ArrayList) RexInputRef(org.apache.calcite.rex.RexInputRef) RexNode(org.apache.calcite.rex.RexNode)

Aggregations

ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Predicate (java.util.function.Predicate)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 RelOptUtil (org.apache.calcite.plan.RelOptUtil)1 RelCollations (org.apache.calcite.rel.RelCollations)1 RelHomogeneousShuttle (org.apache.calcite.rel.RelHomogeneousShuttle)1 RelNode (org.apache.calcite.rel.RelNode)1 SingleRel (org.apache.calcite.rel.SingleRel)1 Aggregate (org.apache.calcite.rel.core.Aggregate)1 AggregateCall (org.apache.calcite.rel.core.AggregateCall)1 SetOp (org.apache.calcite.rel.core.SetOp)1 TableScan (org.apache.calcite.rel.core.TableScan)1