Skip to content

Commit

Permalink
Fix #330
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed Nov 13, 2023
1 parent 37687bf commit 300abd6
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.jena.sparql.algebra.op.OpBGP;
import org.apache.jena.sparql.algebra.op.OpPropFunc;
import org.apache.jena.sparql.algebra.op.OpService;
import org.apache.jena.sparql.algebra.optimize.TransformPropertyFunction;
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.QueryIterator;
import org.apache.jena.sparql.engine.iterator.QueryIterAssign;
Expand Down Expand Up @@ -72,6 +73,8 @@ protected QueryIterator execute(final OpPropFunc opPropFunc, QueryIterator input
protected QueryIterator execute(final OpBGP opBGP, QueryIterator input) {
logger.trace("Execute OpBGP {}", opBGP.getPattern().toString());



if(hasFXSymbols(this.execCxt) && !this.execCxt.getContext().isDefined(FacadeXExecutionContext.hasServiceClause)){
try {
return fxWorkerOpBGP.execute(opBGP, input, this.execCxt);
Expand All @@ -97,7 +100,14 @@ protected QueryIterator execute(final OpBGP opBGP, QueryIterator input) {
return QC.execute(Utils.excludeFXProperties(opBGP), input, new ExecutionContext(execCxt));
}
}

Op opTransformed = TransformPropertyFunction.transform(opBGP, this.execCxt.getContext());
if(!opTransformed.equals(opBGP)){
return super.executeOp(opTransformed, input);
}
logger.trace("Execute with default Jena execution");


// go with the default Jena execution
return super.execute(opBGP, input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static boolean isPropertyOp(Node node) {
return node.isURI() && node.getURI().equals(Triplifier.FACADE_X_TYPE_PROPERTIES);
}

static String queryIteratorToString(QueryIterator q) {
public static String queryIteratorToString(QueryIterator q) {
StringBuilder sb = new StringBuilder();
while (q.hasNext()) {
Binding binding = q.next();
Expand All @@ -69,13 +69,13 @@ static String queryIteratorToString(QueryIterator q) {
return sb.toString();
}

static String printDatasetGraph(DatasetGraph dg){
public static String printDatasetGraph(DatasetGraph dg){
StringBuilder sb = new StringBuilder();
dg.find().forEachRemaining(q-> sb.append(q.toString()).append("\n"));
return sb.toString();
}

static String bindingToString(Binding binding) {
public static String bindingToString(Binding binding) {
StringBuilder sb = new StringBuilder();
Iterator<Var> vars = binding.vars();
while (vars.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -885,5 +885,45 @@ public void testIssue421() throws URISyntaxException, IOException {

}

@Test
public void testIssue330() throws URISyntaxException, IOException {
Dataset ds = DatasetFactory.createGeneral();
QC.setFactory(ARQ.getContext(), FacadeX.ExecutorFactory);
Query query;
String queryStr = IOUtils.toString(Objects.requireNonNull(getClass().getClassLoader().getResource("issues/issue330.sparql")).toURI(), StandardCharsets.UTF_8);
query = QueryFactory.create(queryStr);

// System.out.println(Algebra.compile(query));
// System.out.println(query.toString(Syntax.defaultSyntax));

QueryExecution qExec1 = QueryExecutionFactory.create(query, ds);
// System.out.println(ResultSetFormatter.asText(qExec1.execSelect()));
Set<String> result = new HashSet<>();
ResultSet rs = qExec1.execSelect();
while (rs.hasNext()){
result.add(rs.next().get("a").asLiteral().toString());
}
assertEquals(Sets.newHashSet("abc", "cde"), result);

// Graph g = GraphFactory.createGraphMem();
// g.add(NodeFactory.createBlankNode(), RDF.li(1).asNode(), NodeFactory.createLiteral("abc;cde"));
// Query qq = QueryFactory.create("PREFIX apf: <http://jena.apache.org/ARQ/property#> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?a { ?s rdf:_1 ?o . ?a apf:strSplit(?o \";\") }");
// System.out.println(qq.toString(Syntax.syntaxSPARQL_11));
// Op op = Algebra.compile(qq);
// System.out.println(op);
// OpBGP bgp = (OpBGP) Algebra.parse("(bgp\n" +
// " (triple ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#_1> ?o)\n" +
// " (triple ?a <http://jena.apache.org/ARQ/property#strSplit> ??0)\n" +
// " (triple ??0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> ?o)\n" +
// " (triple ??0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> ??1)\n" +
// " (triple ??1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> \";\")\n" +
// " (triple ??1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil>)\n" +
// " )");
// System.out.println(TransformPropertyFunction.transform(bgp, ARQ.getContext()));
// QueryIterator qi = Algebra.exec(op, g);
// System.out.println(Utils.queryIteratorToString(qi));

}


}
13 changes: 13 additions & 0 deletions sparql-anything-it/src/test/resources/issues/issue330.sparql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
PREFIX fx: <http://sparql.xyz/facade-x/ns/>
PREFIX xyz: <http://sparql.xyz/facade-x/data/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX apf: <http://jena.apache.org/ARQ/property#>
SELECT ?a WHERE {
SERVICE <x-sparql-anything:> {
fx:properties fx:content "abc;cde" .
?s rdf:_1 ?o .
?a apf:strSplit(?o ";") .
}

}

0 comments on commit 300abd6

Please sign in to comment.