-
Notifications
You must be signed in to change notification settings - Fork 156
feat: implement ISO-GQL SAME predicate for element identity compariso… #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
SeasonPilot
wants to merge
4
commits into
apache:master
Choose a base branch
from
SeasonPilot:feature/issue-368-iso-gql-same-predicate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
02099de
feat: implement ISO-GQL SAME predicate for element identity compariso…
SeasonPilot f63e556
Merge branch 'master' of github.com:SeasonPilot/geaflow into feature/…
SeasonPilot f560a46
fix(dsl): resolve ISO-GQL SAME predicate code review issues
SeasonPilot 13d629f
Merge branch 'master' of github.com:SeasonPilot/geaflow into feature/…
SeasonPilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...dsl/geaflow-dsl-parser/src/main/java/org/apache/geaflow/dsl/operator/SqlSameOperator.java
This file contains hidden or 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,78 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.geaflow.dsl.operator; | ||
|
|
||
| import org.apache.calcite.sql.SqlCall; | ||
| import org.apache.calcite.sql.SqlFunction; | ||
| import org.apache.calcite.sql.SqlFunctionCategory; | ||
| import org.apache.calcite.sql.SqlKind; | ||
| import org.apache.calcite.sql.SqlLiteral; | ||
| import org.apache.calcite.sql.SqlNode; | ||
| import org.apache.calcite.sql.SqlWriter; | ||
| import org.apache.calcite.sql.parser.SqlParserPos; | ||
| import org.apache.calcite.sql.type.OperandTypes; | ||
| import org.apache.calcite.sql.type.ReturnTypes; | ||
| import org.apache.geaflow.dsl.sqlnode.SqlSameCall; | ||
|
|
||
| /** | ||
| * SqlOperator for the ISO-GQL SAME predicate function. | ||
| * | ||
| * <p>This operator represents the SAME function which checks element identity. | ||
| * | ||
| * <p>Syntax: SAME(element1, element2, ...) | ||
| * | ||
| * <p>Returns: BOOLEAN - TRUE if all element references point to the same element, | ||
| * FALSE otherwise. | ||
| * | ||
| * <p>Implements ISO/IEC 39075:2024 Section 19.12. | ||
| */ | ||
| public class SqlSameOperator extends SqlFunction { | ||
|
|
||
| public static final SqlSameOperator INSTANCE = new SqlSameOperator(); | ||
|
|
||
| private SqlSameOperator() { | ||
| super( | ||
| "SAME", | ||
| SqlKind.OTHER_FUNCTION, | ||
| ReturnTypes.BOOLEAN, | ||
| null, | ||
| // At least 2 operands, all must be of comparable types | ||
| OperandTypes.VARIADIC, | ||
| SqlFunctionCategory.USER_DEFINED_FUNCTION | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| public SqlCall createCall( | ||
| SqlLiteral functionQualifier, | ||
| SqlParserPos pos, | ||
| SqlNode... operands) { | ||
| return new SqlSameCall(pos, java.util.Arrays.asList(operands)); | ||
| } | ||
|
|
||
| @Override | ||
| public void unparse( | ||
| SqlWriter writer, | ||
| SqlCall call, | ||
| int leftPrec, | ||
| int rightPrec) { | ||
| call.unparse(writer, leftPrec, rightPrec); | ||
| } | ||
| } |
131 changes: 131 additions & 0 deletions
131
...flow-dsl/geaflow-dsl-parser/src/main/java/org/apache/geaflow/dsl/sqlnode/SqlSameCall.java
This file contains hidden or 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,131 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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 org.apache.geaflow.dsl.sqlnode; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import org.apache.calcite.sql.SqlCall; | ||
| import org.apache.calcite.sql.SqlNode; | ||
| import org.apache.calcite.sql.SqlOperator; | ||
| import org.apache.calcite.sql.SqlWriter; | ||
| import org.apache.calcite.sql.parser.SqlParserPos; | ||
| import org.apache.calcite.sql.validate.SqlValidator; | ||
| import org.apache.calcite.sql.validate.SqlValidatorScope; | ||
| import org.apache.geaflow.dsl.operator.SqlSameOperator; | ||
|
|
||
| /** | ||
| * SqlNode representing the ISO-GQL SAME predicate function. | ||
| * | ||
| * <p>The SAME predicate checks if multiple element references point to the same | ||
| * graph element (identity check, not value equality). | ||
| * | ||
| * <p>Syntax: SAME(element_ref1, element_ref2 [, element_ref3, ...]) | ||
| * | ||
| * <p>Example: | ||
| * <pre> | ||
| * MATCH (a:Person)-[:KNOWS]->(b), (b)-[:KNOWS]->(c) | ||
| * WHERE SAME(a, c) | ||
| * RETURN a.name, b.name; | ||
| * </pre> | ||
| * | ||
| * <p>This returns triangular paths where the start and end vertices are the same element. | ||
| * | ||
| * <p>Implements ISO/IEC 39075:2024 Section 19.12 (SAME predicate). | ||
| */ | ||
| public class SqlSameCall extends SqlCall { | ||
|
|
||
| private final List<SqlNode> operands; | ||
|
|
||
| /** | ||
| * Creates a SqlSameCall. | ||
| * | ||
| * @param pos Parser position | ||
| * @param operands List of element reference expressions (must be 2 or more) | ||
| */ | ||
| public SqlSameCall(SqlParserPos pos, List<SqlNode> operands) { | ||
| super(pos); | ||
| // Create a mutable copy to allow setOperand to work | ||
| this.operands = new ArrayList<>(Objects.requireNonNull(operands, "operands")); | ||
|
|
||
| // ISO-GQL requires at least 2 arguments | ||
| if (operands.size() < 2) { | ||
| throw new IllegalArgumentException( | ||
| "SAME predicate requires at least 2 arguments, got: " + operands.size()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public SqlOperator getOperator() { | ||
| return SqlSameOperator.INSTANCE; | ||
| } | ||
|
|
||
| @Override | ||
| public List<SqlNode> getOperandList() { | ||
| return operands; | ||
| } | ||
|
|
||
| @Override | ||
| public void validate(SqlValidator validator, SqlValidatorScope scope) { | ||
| // Validation will be handled by GQLSameValidator | ||
| // This just validates the syntax is correct | ||
| for (SqlNode operand : operands) { | ||
| operand.validate(validator, scope); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void setOperand(int i, SqlNode operand) { | ||
| if (i < 0 || i >= operands.size()) { | ||
| throw new IllegalArgumentException("Invalid operand index: " + i); | ||
| } | ||
| operands.set(i, operand); | ||
| } | ||
|
|
||
| @Override | ||
| public void unparse(SqlWriter writer, int leftPrec, int rightPrec) { | ||
| writer.print("SAME"); | ||
| final SqlWriter.Frame frame = | ||
| writer.startList(SqlWriter.FrameTypeEnum.FUN_CALL, "(", ")"); | ||
|
|
||
| for (int i = 0; i < operands.size(); i++) { | ||
| if (i > 0) { | ||
| writer.sep(","); | ||
| } | ||
| operands.get(i).unparse(writer, 0, 0); | ||
| } | ||
|
|
||
| writer.endList(frame); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the number of operands (element references) in this SAME call. | ||
| */ | ||
| public int getOperandCount() { | ||
| return operands.size(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the operand at the specified index. | ||
| */ | ||
| public SqlNode getOperand(int index) { | ||
| return operands.get(index); | ||
| } | ||
| } |
This file contains hidden or 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
23 changes: 23 additions & 0 deletions
23
geaflow/geaflow-dsl/geaflow-dsl-parser/src/test/resources/IsoGQLSame.sql
This file contains hidden or 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,23 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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. | ||
| */ | ||
|
|
||
| MATCH (a:person)-[:know]->(b:person), (b)-[:know]->(c:person) WHERE SAME(a, c) RETURN a.name, b.name; | ||
| MATCH (a:person)-[:know]->(b:person), (c:person)-[:know]->(d:person) WHERE SAME(a, c) RETURN a.id, b.id, c.id, d.id; | ||
| MATCH (a:person {id: 1})-[e1:know]->(b:person), (c:person)-[e2:know]->(d:person) WHERE SAME(a, b, c) RETURN a.id, b.id; | ||
| MATCH (a:person)-[e1:know]->(b:person)-[e2:know]->(c:person) WHERE SAME(a, c) RETURN a.name, b.name, c.name; |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.