Skip to content

Commit e9ec2aa

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

6 files changed

Lines changed: 5841 additions & 3 deletions

File tree

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

0 commit comments

Comments
 (0)