-
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): Convert Label Condition to Type Constraint (#3441)
<!-- Thanks for your contribution! please review https://github.com/alibaba/GraphScope/blob/main/CONTRIBUTING.md before opening an issue. --> ## What do these changes do? as titled. <!-- Please give a short brief about these changes. --> ## Related issue number <!-- Are there any issues opened that will be resolved by merging this change? --> Fixes #3378 --------- Co-authored-by: Longbin Lai <[email protected]> Co-authored-by: Zhang Lei <[email protected]>
- Loading branch information
1 parent
0435bb8
commit 1b9d100
Showing
18 changed files
with
416 additions
and
115 deletions.
There are no files selected for viewing
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
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
69 changes: 69 additions & 0 deletions
69
...e_engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/GraphRelVisitor.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,69 @@ | ||
/* | ||
* 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.rel; | ||
|
||
import com.alibaba.graphscope.common.ir.rel.graph.*; | ||
import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalMultiMatch; | ||
import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalSingleMatch; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.RelShuttleImpl; | ||
|
||
/** | ||
* the class is used to visit a graph relation tree | ||
*/ | ||
public abstract class GraphRelVisitor extends RelShuttleImpl { | ||
public RelNode visit(GraphLogicalSource source) { | ||
return source; | ||
} | ||
|
||
public RelNode visit(GraphLogicalExpand expand) { | ||
return visitChildren(expand); | ||
} | ||
|
||
public RelNode visit(GraphLogicalExpandDegree degree) { | ||
return visitChildren(degree); | ||
} | ||
|
||
public RelNode visit(GraphLogicalGetV getV) { | ||
return visitChildren(getV); | ||
} | ||
|
||
public RelNode visit(GraphLogicalPathExpand expand) { | ||
return visitChildren(expand); | ||
} | ||
|
||
public RelNode visit(GraphLogicalSingleMatch match) { | ||
return match; | ||
} | ||
|
||
public RelNode visit(GraphLogicalMultiMatch match) { | ||
return match; | ||
} | ||
|
||
public RelNode visit(GraphLogicalAggregate aggregate) { | ||
return visitChildren(aggregate); | ||
} | ||
|
||
public RelNode visit(GraphLogicalProject project) { | ||
return visitChildren(project); | ||
} | ||
|
||
public RelNode visit(GraphLogicalSort sort) { | ||
return visitChildren(sort); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
...engine/compiler/src/main/java/com/alibaba/graphscope/common/ir/rel/PushFilterVisitor.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,107 @@ | ||
/* | ||
* 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.rel; | ||
|
||
import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalExpand; | ||
import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalGetV; | ||
import com.alibaba.graphscope.common.ir.rel.graph.GraphLogicalSource; | ||
import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalMultiMatch; | ||
import com.alibaba.graphscope.common.ir.rel.graph.match.GraphLogicalSingleMatch; | ||
import com.alibaba.graphscope.common.ir.rex.RexGraphVariable; | ||
import com.alibaba.graphscope.common.ir.rex.RexVariableAliasCollector; | ||
import com.alibaba.graphscope.common.ir.tools.AliasInference; | ||
import com.alibaba.graphscope.common.ir.tools.GraphBuilder; | ||
|
||
import org.apache.calcite.rel.RelNode; | ||
import org.apache.calcite.rel.type.RelDataType; | ||
import org.apache.calcite.rel.type.RelDataTypeField; | ||
import org.apache.calcite.rex.RexNode; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* visit a graph relation tree and push filter to the corresponding source | ||
*/ | ||
public class PushFilterVisitor extends GraphRelVisitor { | ||
private final GraphBuilder builder; | ||
private final RexNode condition; | ||
private final List<Integer> distinctAliasIds; | ||
private boolean pushed; | ||
|
||
public PushFilterVisitor(GraphBuilder builder, RexNode condition) { | ||
this.builder = builder; | ||
this.condition = condition; | ||
this.distinctAliasIds = | ||
condition | ||
.accept(new RexVariableAliasCollector<>(true, RexGraphVariable::getAliasId)) | ||
.stream() | ||
.distinct() | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public RelNode visit(GraphLogicalSingleMatch match) { | ||
RelNode sentence = match.getSentence().accept(this); | ||
if (!sentence.equals(match.getSentence())) { | ||
return builder.match(sentence, match.getMatchOpt()).build(); | ||
} | ||
return match; | ||
} | ||
|
||
@Override | ||
public RelNode visit(GraphLogicalMultiMatch match) { | ||
List<RelNode> sentences = | ||
match.getSentences().stream().map(k -> k.accept(this)).collect(Collectors.toList()); | ||
if (!sentences.equals(match.getSentences())) { | ||
return builder.match(sentences.get(0), sentences.subList(1, sentences.size())).build(); | ||
} | ||
return match; | ||
} | ||
|
||
@Override | ||
public RelNode visit(GraphLogicalSource source) { | ||
return fuseFilter(source); | ||
} | ||
|
||
@Override | ||
public RelNode visit(GraphLogicalExpand expand) { | ||
return fuseFilter(visitChildren(expand)); | ||
} | ||
|
||
@Override | ||
public RelNode visit(GraphLogicalGetV getV) { | ||
return fuseFilter(visitChildren(getV)); | ||
} | ||
|
||
public boolean isPushed() { | ||
return pushed; | ||
} | ||
|
||
private RelNode fuseFilter(RelNode node) { | ||
if (distinctAliasIds.size() != 1) return node; | ||
int aliasId = distinctAliasIds.get(0); | ||
RelDataType rowType = node.getRowType(); | ||
for (RelDataTypeField field : rowType.getFieldList()) { | ||
if (aliasId != AliasInference.DEFAULT_ID && field.getIndex() == aliasId) { | ||
pushed = true; | ||
return builder.push(node).filter(condition).build(); | ||
} | ||
} | ||
return node; | ||
} | ||
} |
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.