Skip to content

Commit 6f2c8e2

Browse files
committed
Replaced service enhancer module with the latest snapshot.
1 parent 25d036a commit 6f2c8e2

132 files changed

Lines changed: 12270 additions & 1792 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

jena-serviceenhancer/pom.xml

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
</dependency>
5050

5151
<dependency>
52-
<groupId>junit</groupId>
53-
<artifactId>junit</artifactId>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter</artifactId>
5454
<scope>test</scope>
5555
</dependency>
5656

@@ -111,6 +111,12 @@
111111
<goal>shade</goal>
112112
</goals>
113113
<configuration>
114+
<relocations>
115+
<relocation>
116+
<pattern>com.google</pattern>
117+
<shadedPattern>org.apache.jena.sparql.service.enhancer.shaded.com.google</shadedPattern>
118+
</relocation>
119+
</relocations>
114120
<transformers>
115121
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
116122
<transformer implementation="org.apache.maven.plugins.shade.resource.ApacheLicenseResourceTransformer" />
@@ -138,6 +144,46 @@
138144
</plugins>
139145
</build>
140146
</profile>
147+
148+
<!-- Profile that unpacks the class files from the JAR release of this maven module. -->
149+
<!-- Use the command below to create a shaded Fuseki-Mod plugin jar from this pom.xml alone. -->
150+
<!-- The command execution will attempt to download the necessary JAR files and only operate on them. -->
151+
<!-- The Java source code does not have to be present. -->
152+
<!-- mvn -Punpack-own-classes,bundle -Dmaven.test.skip package -->
153+
<profile>
154+
<id>unpack-own-classes</id>
155+
<build>
156+
<plugins>
157+
<plugin>
158+
<groupId>org.apache.maven.plugins</groupId>
159+
<artifactId>maven-dependency-plugin</artifactId>
160+
<executions>
161+
<execution>
162+
<id>unpack-own-classes</id>
163+
<phase>generate-resources</phase>
164+
<goals>
165+
<goal>unpack</goal>
166+
</goals>
167+
<configuration>
168+
<artifactItems>
169+
<artifactItem>
170+
<groupId>${project.groupId}</groupId>
171+
<artifactId>${project.artifactId}</artifactId>
172+
<version>${project.version}</version>
173+
<type>jar</type>
174+
<overWrite>false</overWrite>
175+
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
176+
</artifactItem>
177+
</artifactItems>
178+
<!-- Skip if classes already exist (normal build with sources) -->
179+
<overWriteIfNewer>false</overWriteIfNewer>
180+
</configuration>
181+
</execution>
182+
</executions>
183+
</plugin>
184+
</plugins>
185+
</build>
186+
</profile>
141187
</profiles>
142188

143189
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*
19+
* SPDX-License-Identifier: Apache-2.0
20+
*/
21+
22+
package org.apache.jena.sparql.service.enhancer.algebra;
23+
24+
import org.apache.jena.sparql.algebra.Op;
25+
import org.apache.jena.sparql.algebra.TransformCopy;
26+
import org.apache.jena.sparql.algebra.op.OpAssign;
27+
import org.apache.jena.sparql.algebra.op.OpExtend;
28+
29+
/**
30+
* Transform OpAssign to OpExtend.
31+
* Rationale: Execution of OpLateral in Jena 5.0.0 inserts OpAssign operations. Attempting to execute those remote results in
32+
* SPARQL LET syntax elements which are usually not understood by remote endpoints.
33+
*/
34+
@Deprecated // Should no longer be necessary with https://github.com/apache/jena/pull/3029
35+
public class TransformAssignToExtend
36+
extends TransformCopy
37+
{
38+
private static TransformAssignToExtend INSTANCE = null;
39+
40+
public static TransformAssignToExtend get() {
41+
if (INSTANCE == null) {
42+
synchronized (TransformAssignToExtend.class) {
43+
if (INSTANCE == null) {
44+
INSTANCE = new TransformAssignToExtend();
45+
}
46+
}
47+
}
48+
return INSTANCE;
49+
}
50+
51+
@Override
52+
public Op transform(OpAssign opAssign, Op subOp) {
53+
return OpExtend.create(subOp, opAssign.getVarExprList());
54+
}
55+
}

jena-serviceenhancer/src/main/java/org/apache/jena/sparql/service/enhancer/algebra/TransformSE_EffectiveOptions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.apache.jena.sparql.algebra.TransformCopy;
2626
import org.apache.jena.sparql.algebra.op.OpService;
2727
import org.apache.jena.sparql.service.enhancer.impl.ServiceOpts;
28+
import org.apache.jena.sparql.service.enhancer.impl.ServiceOptsSE;
2829

2930
/**
3031
* Detects options on SERVICE and materializes them.
@@ -49,7 +50,7 @@ public class TransformSE_EffectiveOptions
4950
@Override
5051
public Op transform(OpService opService, Op subOp) {
5152
OpService tmp = new OpService(opService.getService(), subOp, opService.getSilent());
52-
ServiceOpts so = ServiceOpts.getEffectiveService(tmp);
53+
ServiceOpts so = ServiceOptsSE.getEffectiveService(tmp);
5354
OpService result = so.toService();
5455
return result;
5556
}

jena-serviceenhancer/src/main/java/org/apache/jena/sparql/service/enhancer/algebra/TransformSE_JoinStrategy.java

Lines changed: 87 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*
1919
* SPDX-License-Identifier: Apache-2.0
2020
*/
21-
2221
package org.apache.jena.sparql.service.enhancer.algebra;
2322

2423
import java.util.HashMap;
@@ -45,6 +44,7 @@
4544
import org.apache.jena.sparql.graph.NodeTransform;
4645
import org.apache.jena.sparql.graph.NodeTransformLib;
4746
import 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 &lt;loop:&gt; { }</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
}

jena-serviceenhancer/src/main/java/org/apache/jena/sparql/service/enhancer/algebra/TransformSE_OptimizeSelfJoin.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.jena.sparql.algebra.op.OpService;
2727
import org.apache.jena.sparql.algebra.optimize.Rewrite;
2828
import org.apache.jena.sparql.service.enhancer.impl.ServiceOpts;
29+
import org.apache.jena.sparql.service.enhancer.impl.ServiceOptsSE;
2930
import org.apache.jena.sparql.service.enhancer.init.ServiceEnhancerConstants;
3031

3132
/** It seems that preemtive optimization before execution does not work with property
@@ -44,17 +45,17 @@ public TransformSE_OptimizeSelfJoin(Rewrite selfRewrite) {
4445
@Override
4546
public Op transform(OpService opService, Op subOp) {
4647
Op result;
47-
ServiceOpts so = ServiceOpts.getEffectiveService(
48+
ServiceOpts so = ServiceOptsSE.getEffectiveService(
4849
new OpService(opService.getService(), subOp, opService.getSilent()));
4950

5051
OpService targetService = so.getTargetService();
5152
if (ServiceEnhancerConstants.SELF.equals(targetService.getService())) {
52-
String optimizerOpt = so.getFirstValue(ServiceOpts.SO_OPTIMIZE, "on", "on");
53+
String optimizerOpt = so.getFirstValue(ServiceOptsSE.SO_OPTIMIZE, "on", "on");
5354

5455
if (!optimizerOpt.equalsIgnoreCase("off")) {
5556
Op newSub = selfRewrite.rewrite(targetService.getSubOp());
5657

57-
so.removeKey(ServiceOpts.SO_OPTIMIZE);
58+
so.removeKey(ServiceOptsSE.SO_OPTIMIZE);
5859
// so.add(ServiceOpts.SO_OPTIMIZE, "off");
5960
// so.add(ServiceOpts.SO_OPTIMIZE, "on");
6061
result = new ServiceOpts(

0 commit comments

Comments
 (0)