OmniSciDB  343343d194
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ProjectProjectRemoveRule.java
Go to the documentation of this file.
1 /*
2  * Copyright 2019 OmniSci, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.mapd.calcite.parser;
18 
19 import org.apache.calcite.plan.RelOptRule;
20 import org.apache.calcite.plan.RelOptRuleCall;
21 import org.apache.calcite.plan.hep.HepRelVertex;
22 import org.apache.calcite.rel.RelNode;
23 import org.apache.calcite.rel.core.Project;
24 import org.apache.calcite.rel.core.RelFactories;
25 import org.apache.calcite.rel.rules.ProjectRemoveRule;
26 import org.apache.calcite.tools.RelBuilderFactory;
27 
32 public class ProjectProjectRemoveRule extends RelOptRule {
33  static RelNode unwrap(RelNode node) {
34  if (node instanceof HepRelVertex) {
35  return unwrap(((HepRelVertex) node).getCurrentRel());
36  }
37 
38  return node;
39  }
40 
41  public static final ProjectProjectRemoveRule INSTANCE =
42  new ProjectProjectRemoveRule(RelFactories.LOGICAL_BUILDER);
43 
44  private ProjectRemoveRule innerRule;
45 
51  public ProjectProjectRemoveRule(RelBuilderFactory relBuilderFactory) {
52  super(operandJ(Project.class, null, ProjectRemoveRule::isTrivial, any()),
53  relBuilderFactory,
54  null);
55  innerRule = new ProjectRemoveRule(relBuilderFactory);
56  }
57 
58  @Override
59  public void onMatch(RelOptRuleCall call) {
60  boolean hasParents = null != call.getParents() && !call.getParents().isEmpty();
61  Project project = (Project) call.rel(0);
62  boolean inputIsProject = unwrap(project.getInput()) instanceof Project;
63  if (hasParents || inputIsProject) {
64  innerRule.onMatch(call);
65  }
66  }
67 }
ProjectProjectRemoveRule(RelBuilderFactory relBuilderFactory)