-
Notifications
You must be signed in to change notification settings - Fork 664
GH-3253: Apply transforms to present Elements of ExprFunctionOp instances. #3254
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
Aklakan
wants to merge
1
commit into
apache:main
Choose a base branch
from
Aklakan:2025-06-15_functionop-nodetransform
base: main
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
|
||
import org.apache.jena.graph.Node; | ||
import org.apache.jena.graph.Node_Variable; | ||
|
@@ -48,11 +49,13 @@ | |
*/ | ||
public class ElementTransformSubst extends ElementTransformCopyBase { | ||
private final NodeTransform nodeTransform; | ||
private final Map<Var, ? extends Node> mapping; | ||
|
||
public ElementTransformSubst(Map<Var, ? extends Node> mapping) { | ||
this.mapping = mapping; | ||
this.nodeTransform = new NodeTransformSubst(mapping); | ||
this(new NodeTransformSubst(mapping)); | ||
} | ||
|
||
public ElementTransformSubst(NodeTransform nodeTransform) { | ||
this.nodeTransform = Objects.requireNonNull(nodeTransform); | ||
} | ||
|
||
@Override | ||
|
@@ -144,7 +147,10 @@ public ElementSubQuery transform(ElementSubQuery subQuery, Query newQuery) { | |
public ElementData transform(ElementData data) { | ||
// Check for var-var. If none, no work to do. | ||
List<Var> vars = data.getVars(); | ||
boolean workToDo = vars.stream().anyMatch(v->mapping.containsKey(v)); | ||
boolean workToDo = vars.stream().anyMatch(v-> { | ||
Node n = nodeTransform.apply(v); | ||
return n != null && !v.equals(n); | ||
}); | ||
Comment on lines
+150
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This intent of this change is to remove the need for the explicit Map next to the NodeTransform. |
||
if ( ! workToDo ) | ||
return data; | ||
|
||
|
67 changes: 67 additions & 0 deletions
67
jena-arq/src/test/java/org/apache/jena/sparql/expr/TestExprFunctionOp_ExprTransform.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,67 @@ | ||
/* | ||
* 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.jena.sparql.expr; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.apache.jena.sparql.algebra.walker.Walker; | ||
import org.apache.jena.sparql.expr.TestExprFunctionOp_NodeTransform.ExprFunctionOpValidator; | ||
import org.apache.jena.sparql.util.ExprUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class TestExprFunctionOp_ExprTransform { | ||
private ExprTransform et = new ExprTransformCopy() | ||
{ @Override | ||
public Expr transform(ExprVar exprVar) | ||
{ return new ExprVar(exprVar.getVarName().toUpperCase()) ; } | ||
}; | ||
|
||
@Test public void et_exists_tp_01() { test( "exists { ?s ?p ?o }", "exists { ?s ?p ?o }", et); } | ||
@Test public void et_notExists_tp_01() { test("not exists { ?s ?p ?o }", "notexists { ?s ?p ?o }", et); } | ||
|
||
// Note: The empty graph pattern in "{} FILTER(...)" is used to establish | ||
// syntactic equivalence with the transformation result. | ||
@Test public void et_exists_filter_01() { test( "exists { {} FILTER(?x = ?y) }", "exists { {} FILTER(?X = ?Y) }", et); } | ||
@Test public void et_notExists_filter_01() { test("not exists { {} FILTER(?x = ?y) }", "not exists { {} FILTER(?X = ?Y) }", et); } | ||
|
||
@Test public void et_exists_bind_01() { test( "exists { BIND(?x AS ?y) }", "exists { BIND(?X AS ?y) }", et); } | ||
@Test public void et_notExists_bind_01() { test("not exists { BIND(?x AS ?y) }", "not exists { BIND(?X AS ?y) }", et); } | ||
|
||
@Test public void et_exists_nested_filter_01() { test( "exists { {} FILTER exists { {} FILTER(?x = ?y) } }", "exists { {} FILTER exists { {} FILTER(?X = ?Y) } }", et); } | ||
@Test public void et_notExists_nested_filter_01() { test("not exists { {} FILTER not exists { {} FILTER(?x = ?y) } }", "not exists { {} FILTER not exists { {} FILTER(?X = ?Y) } }", et); } | ||
|
||
private void test(String string, String string2, ExprTransform et) | ||
{ | ||
Expr e1 = ExprUtils.parse(string) ; | ||
Expr e2 = ExprUtils.parse(string2) ; | ||
|
||
Expr e3 = ExprTransformer.transform(et, e1); | ||
|
||
// Check whether syntax and algebra are consistent | ||
ExprVisitor opVisitor = new ExprFunctionOpValidator(); | ||
Walker.walk(e2, opVisitor); | ||
Walker.walk(e3, opVisitor); | ||
|
||
assertEquals(e2, e3) ; | ||
if(!e2.equalsBySyntax(e3)) { | ||
Assert.fail("Objects differ by syntax: " + e2 + " != " + e3); | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could copySubstitute in principle delegate to applyNodeTransform with a NodeTransform based on the binding? Or are there subtle semantic difference?