This is an automated email from the ASF dual-hosted git repository.

andy pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git


The following commit(s) were added to refs/heads/main by this push:
     new 8c6f4f61b7 GH-3028: Use OpExtend (BIND)
8c6f4f61b7 is described below

commit 8c6f4f61b70a5e315eb20c60cc649b123df3c11e
Author: Andy Seaborne <[email protected]>
AuthorDate: Sat Feb 22 18:52:03 2025 +0000

    GH-3028: Use OpExtend (BIND)
---
 .../apache/jena/sparql/algebra/op/OpAssign.java    | 10 +++----
 .../sparql/engine/iterator/QueryIterLateral.java   | 32 ++++++++++++----------
 2 files changed, 23 insertions(+), 19 deletions(-)

diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpAssign.java 
b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpAssign.java
index 8a4a3f18bb..0680509825 100644
--- a/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpAssign.java
+++ b/jena-arq/src/main/java/org/apache/jena/sparql/algebra/op/OpAssign.java
@@ -34,9 +34,9 @@ public class OpAssign extends OpExtendAssign {
     // Not possible if it's the reassignment of something already assigned.
 
     /** Create an OpAssign or add to an existing one.
-     * This cooperation collapses what would otherwise be stacks
-     * of OpExtend.
-     */ 
+     * This operation collapses what would otherwise be
+     * stacks of OpAssign.
+     */
     static public Op assign(Op op, Var var, Expr expr) {
         if ( !(op instanceof OpAssign) )
             return create(op, var, expr);
@@ -54,7 +54,7 @@ public class OpAssign extends OpExtendAssign {
     /** Create an v or add to an existing one.
      * This operation collapses what would otherwise be stacks
      * of OpAssign.
-     */ 
+     */
     static public Op assign(Op op, VarExprList exprs) {
         if ( !(op instanceof OpAssign) )
             return create(op, exprs);
@@ -102,7 +102,7 @@ public class OpAssign extends OpExtendAssign {
         OpAssign op = new OpAssign(subOp, new VarExprList(getVarExprList()));
         return op;
     }
-    
+
     @Override
     public boolean equalTo(Op other, NodeIsomorphismMap labelMap) {
         if ( !(other instanceof OpAssign) )
diff --git 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterLateral.java
 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterLateral.java
index d6944c2c93..c030759e13 100644
--- 
a/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterLateral.java
+++ 
b/jena-arq/src/main/java/org/apache/jena/sparql/engine/iterator/QueryIterLateral.java
@@ -54,12 +54,22 @@ public class QueryIterLateral extends QueryIterRepeatApply {
         this.isUnit = isJoinIdentity(subOp);
     }
 
-    private boolean isJoinIdentity(Op op) {
+    private static boolean isJoinIdentity(Op op) {
         if( ! ( op instanceof OpTable table ) )
             return false;
         return table.isJoinIdentity();
     }
 
+    /** Choice of variable setting */
+    private static Op assignments(Op op, VarExprList varExprs) {
+        // Assign (LET) is safer (it is not an error to assign to variable if 
already
+        // set to the same term) but this operation is not portable.
+        //return OpAssign.create(op, varExprs);
+
+        // BIND
+        return OpExtend.create(op, varExprs);
+    }
+
     @Override
     protected QueryIterator nextStage(Binding binding) {
         if ( isUnit )
@@ -114,7 +124,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
             Op opExec = substitute
                     ? Substitute.substitute(opBGP, substitutions)
                     : opBGP;
-            opExec = OpAssign.create(opExec, assigns);
+            opExec = assignments(opExec, assigns);
             return opExec;
         }
 
@@ -145,12 +155,10 @@ public class QueryIterLateral extends 
QueryIterRepeatApply {
                 Binding substitutions = builder.build();
                 opExec = Substitute.substitute(opQuadPattern, substitutions);
             }
-            opExec = OpAssign.create(opExec, assigns);
+            opExec = assignments(opExec, assigns);
             return opExec;
         }
 
-        // XXX Extract - do one node
-
         @Override
         public Op transform(OpService opService, Op subOp) {
             Node g = opService.getService();
@@ -173,7 +181,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
                 op2 = new OpService(g2, subOp, opService.getSilent());
             } else
                 op2 = new OpService(g, subOp, opService.getSilent());
-            Op opExec = OpAssign.create(op2, assigns);
+            Op opExec = assignments(op2, assigns);
             return opExec;
         }
 
@@ -199,7 +207,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
                 op2 = new OpGraph(g2, subOp);
             } else
                 op2 = new OpGraph(g, subOp);
-            Op opExec = OpAssign.create(op2, assigns);
+            Op opExec = assignments(op2, assigns);
             return opExec;
         }
 
@@ -231,7 +239,6 @@ public class QueryIterLateral extends QueryIterRepeatApply {
             if ( path.isTriple() ) {
                 Triple t1 = path.asTriple();
                 generateAssignmentTriple(t1, assigns, builder);
-                // XXX Triple t2 = Substitute.substitute(triple, binding);
                 Triple t2 = applyReplacement(t1, replacement);
                 if ( t1.equals(t2) )
                     return opPath;
@@ -255,7 +262,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
             Node o2 = applyReplacement(o, replacement);
             TriplePath path2 = new TriplePath(s2, path.getPath(), o2);
             Op op2 = new OpPath(path2);
-            Op opExec = OpAssign.create(op2, assigns);
+            Op opExec = assignments(op2, assigns);
             return opExec;
         }
 
@@ -271,7 +278,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
             if ( substitute )
                 t2 = applyReplacement(triple, replacement);
             Op op2 = new OpTriple(t2);
-            Op opExec = OpAssign.create(op2, assigns);
+            Op opExec = assignments(op2, assigns);
             return opExec;
         }
 
@@ -349,9 +356,6 @@ public class QueryIterLateral extends QueryIterRepeatApply {
 //
 //            Triple triple2 = Triple.create(s, p, o);
 //            return triple2;
-//        }
-
-        // XXX Other, non-std, ops.
 
         private void generateAssignmentNode(Node n, VarExprList assigns, 
BindingBuilder builder) {
             if ( n == null )
@@ -371,7 +375,7 @@ public class QueryIterLateral extends QueryIterRepeatApply {
             }
         }
 
-        // XXX Needed? To avoid object allocation.
+        // Avoid object allocation.
         private boolean workToDo(Node n) {
             if ( n == null )
                 return false;

Reply via email to