Skip to content

Commit ce4a168

Browse files
committed
[FLINK-39285][table] Ignore project rel node generated by FlinkFilterJoinRule in JoinToMultiJoinRule
1 parent b26c398 commit ce4a168

6 files changed

Lines changed: 5838 additions & 3 deletions

File tree

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to you under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.calcite.rel.logical;
18+
19+
import com.google.common.collect.ImmutableList;
20+
import com.google.common.collect.ImmutableSet;
21+
import org.apache.calcite.plan.Convention;
22+
import org.apache.calcite.plan.RelOptCluster;
23+
import org.apache.calcite.plan.RelTraitSet;
24+
import org.apache.calcite.rel.RelCollationTraitDef;
25+
import org.apache.calcite.rel.RelCollations;
26+
import org.apache.calcite.rel.RelInput;
27+
import org.apache.calcite.rel.RelNode;
28+
import org.apache.calcite.rel.RelShuttle;
29+
import org.apache.calcite.rel.core.CorrelationId;
30+
import org.apache.calcite.rel.core.Project;
31+
import org.apache.calcite.rel.hint.RelHint;
32+
import org.apache.calcite.rel.metadata.RelMdCollation;
33+
import org.apache.calcite.rel.metadata.RelMetadataQuery;
34+
import org.apache.calcite.rel.type.RelDataType;
35+
import org.apache.calcite.rex.RexNode;
36+
import org.apache.calcite.rex.RexUtil;
37+
import org.apache.calcite.sql.validate.SqlValidatorUtil;
38+
import org.apache.calcite.util.Util;
39+
import org.checkerframework.checker.nullness.qual.Nullable;
40+
41+
import java.util.List;
42+
import java.util.Set;
43+
44+
/**
45+
* Sub-class of {@link org.apache.calcite.rel.core.Project} not targeted at any particular engine or
46+
* calling convention.
47+
*/
48+
public final class LogicalProject extends Project {
49+
// ~ Constructors -----------------------------------------------------------
50+
51+
/**
52+
* Creates a LogicalProject.
53+
*
54+
* <p>Use {@link #create} unless you know what you're doing.
55+
*
56+
* @param cluster Cluster this relational expression belongs to
57+
* @param traitSet Traits of this relational expression
58+
* @param hints Hints of this relational expression
59+
* @param input Input relational expression
60+
* @param projects List of expressions for the input columns
61+
* @param rowType Output row type
62+
* @param variablesSet Correlation variables set by this relational expression to be used by
63+
* nested expressions
64+
*/
65+
public LogicalProject(
66+
RelOptCluster cluster,
67+
RelTraitSet traitSet,
68+
List<RelHint> hints,
69+
RelNode input,
70+
List<? extends RexNode> projects,
71+
RelDataType rowType,
72+
Set<CorrelationId> variablesSet) {
73+
super(cluster, traitSet, hints, input, projects, rowType, variablesSet);
74+
assert traitSet.containsIfApplicable(Convention.NONE);
75+
}
76+
77+
@Deprecated // to be removed before 2.0
78+
public LogicalProject(
79+
RelOptCluster cluster,
80+
RelTraitSet traitSet,
81+
List<RelHint> hints,
82+
RelNode input,
83+
List<? extends RexNode> projects,
84+
RelDataType rowType) {
85+
this(cluster, traitSet, hints, input, projects, rowType, ImmutableSet.of());
86+
}
87+
88+
@Deprecated // to be removed before 2.0
89+
public LogicalProject(
90+
RelOptCluster cluster,
91+
RelTraitSet traitSet,
92+
RelNode input,
93+
List<? extends RexNode> projects,
94+
RelDataType rowType) {
95+
this(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
96+
}
97+
98+
@Deprecated // to be removed before 2.0
99+
public LogicalProject(
100+
RelOptCluster cluster,
101+
RelTraitSet traitSet,
102+
RelNode input,
103+
List<? extends RexNode> projects,
104+
RelDataType rowType,
105+
int flags) {
106+
this(cluster, traitSet, ImmutableList.of(), input, projects, rowType, ImmutableSet.of());
107+
Util.discard(flags);
108+
}
109+
110+
@Deprecated // to be removed before 2.0
111+
public LogicalProject(
112+
RelOptCluster cluster,
113+
RelNode input,
114+
List<RexNode> projects,
115+
@Nullable List<? extends @Nullable String> fieldNames,
116+
int flags) {
117+
this(
118+
cluster,
119+
cluster.traitSetOf(RelCollations.EMPTY),
120+
ImmutableList.of(),
121+
input,
122+
projects,
123+
RexUtil.createStructType(cluster.getTypeFactory(), projects, fieldNames, null),
124+
ImmutableSet.of());
125+
Util.discard(flags);
126+
}
127+
128+
/** Creates a LogicalProject by parsing serialized output. */
129+
public LogicalProject(RelInput input) {
130+
super(input);
131+
}
132+
133+
// ~ Methods ----------------------------------------------------------------
134+
135+
/**
136+
* Creates a LogicalProject.
137+
*
138+
* @deprecated Use {@link #create(RelNode, List, List, List, Set)} instead
139+
*/
140+
@Deprecated // to be removed before 2.0
141+
public static LogicalProject create(
142+
final RelNode input,
143+
List<RelHint> hints,
144+
final List<? extends RexNode> projects,
145+
@Nullable List<? extends @Nullable String> fieldNames) {
146+
return create(input, hints, projects, fieldNames, ImmutableSet.of());
147+
}
148+
149+
/** Creates a LogicalProject. */
150+
public static LogicalProject create(
151+
final RelNode input,
152+
List<RelHint> hints,
153+
final List<? extends RexNode> projects,
154+
@Nullable List<? extends @Nullable String> fieldNames,
155+
final Set<CorrelationId> variablesSet) {
156+
final RelOptCluster cluster = input.getCluster();
157+
final RelDataType rowType =
158+
RexUtil.createStructType(
159+
cluster.getTypeFactory(),
160+
projects,
161+
fieldNames,
162+
SqlValidatorUtil.F_SUGGESTER);
163+
return create(input, hints, projects, rowType, variablesSet);
164+
}
165+
166+
/**
167+
* Creates a LogicalProject, specifying row type rather than field names.
168+
*
169+
* @deprecated Use {@link #create(RelNode, List, List, RelDataType, Set)} instead
170+
*/
171+
@Deprecated // to be removed before 2.0
172+
public static LogicalProject create(
173+
final RelNode input,
174+
List<RelHint> hints,
175+
final List<? extends RexNode> projects,
176+
RelDataType rowType) {
177+
return create(input, hints, projects, rowType, ImmutableSet.of());
178+
}
179+
180+
/** Creates a LogicalProject, specifying row type rather than field names. */
181+
public static LogicalProject create(
182+
final RelNode input,
183+
List<RelHint> hints,
184+
final List<? extends RexNode> projects,
185+
RelDataType rowType,
186+
final Set<CorrelationId> variablesSet) {
187+
final RelOptCluster cluster = input.getCluster();
188+
final RelMetadataQuery mq = cluster.getMetadataQuery();
189+
final RelTraitSet traitSet =
190+
cluster.traitSet()
191+
.replace(Convention.NONE)
192+
.replaceIfs(
193+
RelCollationTraitDef.INSTANCE,
194+
() -> RelMdCollation.project(mq, input, projects));
195+
return new LogicalProject(cluster, traitSet, hints, input, projects, rowType, variablesSet);
196+
}
197+
198+
@Override
199+
public LogicalProject copy(
200+
RelTraitSet traitSet, RelNode input, List<RexNode> projects, RelDataType rowType) {
201+
LogicalProject project =
202+
new LogicalProject(getCluster(), traitSet, hints, input, projects, rowType);
203+
project.setIgnoreForMultiJoin(this.canBeIgnoredForMultiJoin);
204+
return project;
205+
}
206+
207+
@Override
208+
public RelNode accept(RelShuttle shuttle) {
209+
return shuttle.visit(this);
210+
}
211+
212+
@Override
213+
public RelNode withHints(List<RelHint> hintList) {
214+
return new LogicalProject(
215+
getCluster(), traitSet, hintList, input, getProjects(), getRowType(), variablesSet);
216+
}
217+
218+
@Override
219+
public boolean deepEquals(@Nullable Object obj) {
220+
return deepEquals0(obj);
221+
}
222+
223+
@Override
224+
public int deepHashCode() {
225+
return deepHashCode0();
226+
}
227+
228+
// BEGIN FLINK MODIFICATION
229+
230+
private boolean canBeIgnoredForMultiJoin = false;
231+
232+
public void setIgnoreForMultiJoin(boolean canBeIgnoredForMultiJoin) {
233+
this.canBeIgnoredForMultiJoin = canBeIgnoredForMultiJoin;
234+
}
235+
236+
public boolean canBeIgnoredForMultiJoin() {
237+
return canBeIgnoredForMultiJoin;
238+
}
239+
240+
// END FLINK MODIFICATION
241+
242+
}

0 commit comments

Comments
 (0)