-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(interactive): Implement Field Trimmer Rule in Compiler (#3200)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? <!-- Please give a short brief about these changes. --> ## Related issue number #3137 <!-- Are there any issues opened that will be resolved by merging this change? --> Just a draft pr for pre-review --------- Co-authored-by: shirly121 <[email protected]>
- Loading branch information
Showing
8 changed files
with
1,151 additions
and
5 deletions.
There are no files selected for viewing
769 changes: 769 additions & 0 deletions
769
...ne/compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/GraphFieldTrimmer.java
Large diffs are not rendered by default.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
.../compiler/src/main/java/com/alibaba/graphscope/common/ir/planner/rules/FieldTrimRule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2020 Alibaba Group Holding Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.alibaba.graphscope.common.ir.planner.rules; | ||
|
||
import com.alibaba.graphscope.common.ir.planner.GraphFieldTrimmer; | ||
import com.alibaba.graphscope.common.ir.tools.GraphBuilder; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
|
||
public abstract class FieldTrimRule { | ||
public static RelNode trim(GraphBuilder builder, RelNode rel) { | ||
final GraphFieldTrimmer trimmer = new GraphFieldTrimmer(builder); | ||
return trimmer.trim(rel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...e/compiler/src/main/java/com/alibaba/graphscope/common/ir/rex/RexPermuteGraphShuttle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.alibaba.graphscope.common.ir.rex; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rex.RexInputRef; | ||
import org.apache.calcite.rex.RexNode; | ||
import org.apache.calcite.rex.RexPermuteInputsShuttle; | ||
import org.apache.calcite.util.mapping.Mappings; | ||
|
||
public class RexPermuteGraphShuttle extends RexPermuteInputsShuttle { | ||
private final Mappings.TargetMapping mapping; | ||
|
||
/** | ||
* Creates a RexPermuteInputsShuttle. | ||
* | ||
* <p>The mapping provides at most one target for every source. If a source | ||
* has no targets and is referenced in the expression, | ||
* {@link Mappings.TargetMapping#getTarget(int)} | ||
* will give an error. Otherwise the mapping gives a unique target. | ||
* | ||
* @param mapping Mapping | ||
* @param inputs Input relational expressions | ||
*/ | ||
public RexPermuteGraphShuttle(Mappings.TargetMapping mapping, RelNode... inputs) { | ||
super(mapping, inputs); | ||
this.mapping = mapping; | ||
} | ||
|
||
@Override | ||
public RexNode visitInputRef(RexInputRef local) { | ||
final int index = local.getIndex(); | ||
int target = mapping.getTarget(index); | ||
return (local instanceof RexGraphVariable) | ||
? visitGraphVariable((RexGraphVariable) local) | ||
: new RexInputRef(target, local.getType()); | ||
} | ||
|
||
public RexNode visitGraphVariable(RexGraphVariable variable) { | ||
final int index = variable.getIndex(); // resource column id | ||
int target = mapping.getTarget(index); | ||
|
||
return variable.getProperty() == null | ||
? RexGraphVariable.of( | ||
variable.getAliasId(), target, variable.getName(), variable.getType()) | ||
: RexGraphVariable.of( | ||
variable.getAliasId(), | ||
variable.getProperty(), | ||
target, | ||
variable.getName(), | ||
variable.getType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.