1818 *
1919 * SPDX-License-Identifier: Apache-2.0
2020 */
21-
2221package org .apache .jena .sparql .service .enhancer .algebra ;
2322
2423import java .util .HashMap ;
4544import org .apache .jena .sparql .graph .NodeTransform ;
4645import org .apache .jena .sparql .graph .NodeTransformLib ;
4746import org .apache .jena .sparql .service .enhancer .impl .ServiceOpts ;
47+ import org .apache .jena .sparql .service .enhancer .impl .ServiceOptsSE ;
4848
4949/**
5050 * Checks for the presence of <code>SERVICE <loop:> { }</code>
@@ -66,11 +66,22 @@ public Op transform(OpJoin opJoin, Op left, Op right)
6666 Op effectiveRight = right ;
6767 if (right instanceof OpService ) {
6868 OpService op = (OpService )right ;
69- ServiceOpts opts = ServiceOpts .getEffectiveService (op );
70- canDoLinear = opts .containsKey (ServiceOpts .SO_LOOP );
69+ ServiceOpts opts = ServiceOptsSE .getEffectiveService (op );
70+ canDoLinear = opts .containsKey (ServiceOptsSE .SO_LOOP );
7171 if (canDoLinear ) {
72- NodeTransform joinVarRename = renameForImplicitJoinVars (left );
73- effectiveRight = NodeTransformLib .transform (joinVarRename , right );
72+ String loopMode = opts .getFirstValue (ServiceOptsSE .SO_LOOP , "" , null );
73+ switch (loopMode ) {
74+ case "" :
75+ NodeTransform joinVarRename = renameForImplicitJoinVars (left );
76+ effectiveRight = NodeTransformLib .transform (joinVarRename , right );
77+ break ;
78+ case ServiceOptsSE .SO_LOOP_MODE_SCOPED :
79+ // Nothing to do
80+ effectiveRight = right ;
81+ break ;
82+ default :
83+ throw new RuntimeException ("Unsupported loop mode: " + loopMode );
84+ }
7485 }
7586 }
7687
@@ -92,11 +103,21 @@ public Op transform(OpSequence opSequence, List<Op> elts) {
92103 Op newOp = right ;
93104 if (right instanceof OpService ) {
94105 OpService op = (OpService )right ;
95- ServiceOpts opts = ServiceOpts .getEffectiveService (op );
96- boolean isLoop = opts .containsKey (ServiceOpts .SO_LOOP );
106+ ServiceOpts opts = ServiceOptsSE .getEffectiveService (op );
107+ boolean isLoop = opts .containsKey (ServiceOptsSE .SO_LOOP );
97108 if (isLoop ) {
98- NodeTransform joinVarRename = renameForImplicitJoinVars (visibleVarsLeft );
99- newOp = NodeTransformLib .transform (joinVarRename , right );
109+ String loopMode = opts .getFirstValue (ServiceOptsSE .SO_LOOP , "" , null );
110+ switch (loopMode ) {
111+ case "" :
112+ NodeTransform joinVarRename = renameForImplicitJoinVars (visibleVarsLeft );
113+ newOp = NodeTransformLib .transform (joinVarRename , right );
114+ break ;
115+ case ServiceOptsSE .SO_LOOP_MODE_SCOPED :
116+ // Nothing to do
117+ break ;
118+ default :
119+ throw new RuntimeException ("Unsupported loop mode: " + loopMode );
120+ }
100121 }
101122 }
102123
@@ -110,33 +131,44 @@ public Op transform(OpSequence opSequence, List<Op> elts) {
110131 return result ;
111132 }
112133
113- @ Override
114- public Op transform (OpDisjunction opSequence , List <Op > elts ) {
115- // Accumulated visible vars
116- Set <Var > visibleVarsLeft = new LinkedHashSet <>();
117-
118- OpDisjunction result = OpDisjunction .create ();
119- for (Op right : elts ) {
120- Op newOp = right ;
121- if (right instanceof OpService ) {
122- OpService op = (OpService )right ;
123- ServiceOpts opts = ServiceOpts .getEffectiveService (op );
124- boolean isLoop = opts .containsKey (ServiceOpts .SO_LOOP );
125- if (isLoop ) {
126- NodeTransform joinVarRename = renameForImplicitJoinVars (visibleVarsLeft );
127- newOp = NodeTransformLib .transform (joinVarRename , right );
128- }
129- }
130-
131- // Add the now visible vars as new ones
132- Set <Var > visibleVarsRight = OpVars .visibleVars (newOp );
133- visibleVarsLeft .addAll (visibleVarsRight );
134-
135- result .add (newOp );
136- }
137-
138- return result ;
139- }
134+ // @Override
135+ // public Op transform(OpDisjunction opSequence, List<Op> elts) {
136+ // // Accumulated visible vars
137+ // Set<Var> visibleVarsLeft = new LinkedHashSet<>();
138+ //
139+ // OpDisjunction result = OpDisjunction.create();
140+ // for (Op right : elts) {
141+ // Op newOp = right;
142+ // if (right instanceof OpService) {
143+ // OpService op = (OpService)right;
144+ // ServiceOpts opts = ServiceOptsSE.getEffectiveService(op);
145+ // boolean isLoop = opts.containsKey(ServiceOptsSE.SO_LOOP);
146+ // if (isLoop) {
147+ // String loopMode = opts.getFirstValue(ServiceOptsSE.SO_LOOP, "", null);
148+ // switch (loopMode) {
149+ // case "":
150+ // NodeTransform joinVarRename = renameForImplicitJoinVars(visibleVarsLeft);
151+ // newOp = NodeTransformLib.transform(joinVarRename, right);
152+ // break;
153+ // case ServiceOptsSE.SO_LOOP_MODE_SCOPED:
154+ // // Nothing to do
155+ // newOp = right;
156+ // break;
157+ // default:
158+ // throw new RuntimeException("Unsupported loop mode: " + loopMode);
159+ // }
160+ // }
161+ // }
162+ //
163+ // // Add the now visible vars as new ones
164+ // Set<Var> visibleVarsRight = OpVars.visibleVars(newOp);
165+ // visibleVarsLeft.addAll(visibleVarsRight);
166+ //
167+ // result.add(newOp);
168+ // }
169+ //
170+ // return result;
171+ // }
140172
141173 @ Override
142174 public Op transform (OpLeftJoin opLeftJoin , Op left , Op right )
@@ -145,16 +177,26 @@ public Op transform(OpLeftJoin opLeftJoin, Op left, Op right)
145177 Op effectiveRight = right ;
146178 if (right instanceof OpService ) {
147179 OpService op = (OpService )right ;
148- ServiceOpts opts = ServiceOpts .getEffectiveService (op );
149- canDoLinear = opts .containsKey (ServiceOpts .SO_LOOP );
180+ ServiceOpts opts = ServiceOptsSE .getEffectiveService (op );
181+ canDoLinear = opts .containsKey (ServiceOptsSE .SO_LOOP );
150182 if (canDoLinear ) {
151- NodeTransform joinVarRename = renameForImplicitJoinVars (left );
152- effectiveRight = NodeTransformLib .transform (joinVarRename , right );
153-
154- ExprList joinExprs = opLeftJoin .getExprs ();
155- if (joinExprs != null ) {
156- ExprList effectiveExprs = NodeTransformLib .transform (joinVarRename , joinExprs );
157- effectiveRight = OpFilter .filterBy (effectiveExprs , effectiveRight );
183+ String loopMode = opts .getFirstValue (ServiceOptsSE .SO_LOOP , "" , null );
184+ switch (loopMode ) {
185+ case "" :
186+ NodeTransform joinVarRename = renameForImplicitJoinVars (left );
187+ effectiveRight = NodeTransformLib .transform (joinVarRename , right );
188+
189+ ExprList joinExprs = opLeftJoin .getExprs ();
190+ if (joinExprs != null ) {
191+ ExprList effectiveExprs = NodeTransformLib .transform (joinVarRename , joinExprs );
192+ effectiveRight = OpFilter .filterBy (effectiveExprs , effectiveRight );
193+ }
194+ break ;
195+ case ServiceOptsSE .SO_LOOP_MODE_SCOPED :
196+ // Nothing to do
197+ break ;
198+ default :
199+ throw new RuntimeException ("Unsupported loop mode: " + loopMode );
158200 }
159201 }
160202 }
0 commit comments