Skip to content
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

Construct query creating RDFstar statements in memory store does not work anymore with RDF4J 4.1 #4112

Closed
jetztgradnet opened this issue Aug 9, 2022 · 4 comments · Fixed by #4117
Assignees
Labels
🐞 bug issue is a bug
Milestone

Comments

@jetztgradnet
Copy link

jetztgradnet commented Aug 9, 2022

Current Behavior

Running a CONSTRUCT query in a memory store fails to create RDFstar statements with RDF4J 4.1 with the following error:

java.lang.IllegalArgumentException: Node is not a child node: Var (name=s)

The example query:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX person: <http://example.com/person/>
PREFIX org: <http://example.com/org/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
CONSTRUCT {
  ?s ?p ?o.
  << ?s ?p ?o >> <http://example.com/certainty> ?cert.
  << ?s ?p ?o >> <http://example.com/certaintyDeviation> ?certDiv.
  << person:alice foaf:knows person:bob >> <http://example.com/observedBy> person:mike.
}
WHERE {
  {
    SELECT ?s ?p ?o ?cert ?certDiv WHERE {
      VALUES (?s ?p ?o ?cert ?certDiv) {
        (person:alice foaf:knows person:bob "1.0"^^xsd:decimal 0 )
        (person:alice foaf:knows person:carol "0.3"^^xsd:decimal "0.1"^^xsd:decimal)
        (person:carol foaf:knows person:mike "0.7"^^xsd:decimal "0.2"^^xsd:decimal)
        (person:mike foaf:knows person:carol "0.1"^^xsd:decimal UNDEF)
        (person:bob foaf:knows person:carol "0.8"^^xsd:decimal UNDEF)
        (person:alice foaf:knows person:mike "0.6"^^xsd:decimal "0.1"^^xsd:decimal)
        (person:alice foaf:member org:W3C UNDEF UNDEF)
        (person:mike foaf:member org:W3C UNDEF UNDEF)
        (person:alice rdf:type foaf:Person UNDEF UNDEF)
        (person:carol rdf:type foaf:Person UNDEF UNDEF)
        (person:mike rdf:type foaf:Person UNDEF UNDEF)
        (person:bob rdf:type foaf:Person UNDEF UNDEF)
        (org:W3C rdf:type foaf:Organization UNDEF UNDEF)
        (person:alice rdfs:label "Alice" UNDEF UNDEF)
        (person:alice foaf:birthday "1990-01-01" UNDEF UNDEF)
        (person:bob rdfs:label "Bob" UNDEF UNDEF)
        (person:carol rdfs:label "Carol" UNDEF UNDEF)
        (person:mike rdfs:label "Mike" UNDEF UNDEF)
      }
    }
  }
}

This worked previously with RDF4J 4.0. Removing the 3 lines creating RDFstar statements in the CONSTRUCT clause also makes it work with 4.1, but it doesn't accept the RDFstar patterns, not even the "static" one (last one in the example above) without any variables.
This query works fine with current versions of GraphDB (9.x and 10) and Stardog.

Parsing the query fails with this stacktrace:

java.lang.IllegalArgumentException: Node is not a child node: Var (name=s)

	at org.eclipse.rdf4j.query.algebra.AbstractQueryModelNode.replaceChildNode(AbstractQueryModelNode.java:93)
	at org.eclipse.rdf4j.query.algebra.Var.replaceWith(Var.java:126)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meet(ArrayBindingBasedQueryEvaluationContext.java:267)
	at org.eclipse.rdf4j.query.algebra.Var.visit(Var.java:97)
	at org.eclipse.rdf4j.query.algebra.ValueExprTripleRef.visitChildren(ValueExprTripleRef.java:50)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meetUnsupported(AbstractSimpleQueryModelVisitor.java:539)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meetOther(AbstractSimpleQueryModelVisitor.java:534)
	at org.eclipse.rdf4j.query.algebra.ValueExprTripleRef.visit(ValueExprTripleRef.java:85)
	at org.eclipse.rdf4j.query.algebra.ExtensionElem.visitChildren(ExtensionElem.java:64)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meet(AbstractSimpleQueryModelVisitor.java:237)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meet(ArrayBindingBasedQueryEvaluationContext.java:308)
	at org.eclipse.rdf4j.query.algebra.ExtensionElem.visit(ExtensionElem.java:59)
	at org.eclipse.rdf4j.query.algebra.Extension.visitChildren(Extension.java:101)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meetUnaryTupleOperator(ArrayBindingBasedQueryEvaluationContext.java:284)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meet(AbstractSimpleQueryModelVisitor.java:232)
	at org.eclipse.rdf4j.query.algebra.Extension.visit(Extension.java:94)
	at org.eclipse.rdf4j.query.algebra.UnaryTupleOperator.visitChildren(UnaryTupleOperator.java:82)
	at org.eclipse.rdf4j.query.algebra.MultiProjection.visitChildren(MultiProjection.java:113)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meetUnaryTupleOperator(ArrayBindingBasedQueryEvaluationContext.java:284)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meet(AbstractSimpleQueryModelVisitor.java:383)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meet(ArrayBindingBasedQueryEvaluationContext.java:293)
	at org.eclipse.rdf4j.query.algebra.MultiProjection.visit(MultiProjection.java:104)
	at org.eclipse.rdf4j.query.algebra.UnaryTupleOperator.visitChildren(UnaryTupleOperator.java:82)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext$1.meetUnaryTupleOperator(ArrayBindingBasedQueryEvaluationContext.java:284)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meet(AbstractSimpleQueryModelVisitor.java:434)
	at org.eclipse.rdf4j.query.algebra.Reduced.visit(Reduced.java:32)
	at org.eclipse.rdf4j.query.algebra.UnaryTupleOperator.visitChildren(UnaryTupleOperator.java:82)
	at org.eclipse.rdf4j.query.algebra.helpers.AbstractSimpleQueryModelVisitor.meet(AbstractSimpleQueryModelVisitor.java:429)
	at org.eclipse.rdf4j.query.algebra.QueryRoot.visit(QueryRoot.java:48)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.ArrayBindingBasedQueryEvaluationContext.findAllVariablesUsedInQuery(ArrayBindingBasedQueryEvaluationContext.java:321)
	at org.eclipse.rdf4j.query.algebra.evaluation.impl.StrictEvaluationStrategy.precompile(StrictEvaluationStrategy.java:322)
	at org.eclipse.rdf4j.sail.base.SailSourceConnection.evaluateInternal(SailSourceConnection.java:250)
	at org.eclipse.rdf4j.sail.helpers.AbstractSailConnection.evaluate(AbstractSailConnection.java:314)
	at org.eclipse.rdf4j.repository.sail.SailGraphQuery.evaluate(SailGraphQuery.java:61)
	at com.metaphacts.repository.MemoryStoreRDFStarTest.testMemoryStore_RDFstar(MemoryStoreRDFStarTest.java:61)
...

Expected Behavior

Being able to create RDFstar statements in a CONSTRUCT query.

Steps To Reproduce

  1. Set up a project with RDF4J 4.1
  2. run this unit test:
package com.metaphacts.repository;

import static org.junit.Assert.fail;

import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.query.GraphQuery;
import org.eclipse.rdf4j.query.GraphQueryResult;
import org.eclipse.rdf4j.repository.Repository;
import org.eclipse.rdf4j.repository.RepositoryConnection;
import org.eclipse.rdf4j.repository.sail.SailRepository;
import org.eclipse.rdf4j.sail.memory.MemoryStore;
import org.junit.Test;

public class MemoryStoreRDFStarTest {
    @Test
    public void testMemoryStore_RDFstar() throws Exception {
        // @formatter:off
        final String queryString = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>\n"
                + "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>\n"
                + "PREFIX person: <http://example.com/person/>\n"
                + "PREFIX org: <http://example.com/org/>\n"
                + "PREFIX foaf: <http://xmlns.com/foaf/0.1/>\n"
                + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>\n"
                + "CONSTRUCT {\n"
                + "  ?s ?p ?o.\n"
                + "  << ?s ?p ?o >> <http://example.com/certainty> ?cert.\n"
                + "  << ?s ?p ?o >> <http://example.com/certaintyDeviation> ?certDiv.\n"
                + "  << person:alice foaf:knows person:bob >> <http://example.com/observedBy> person:mike.\n"
                + "}\n"
                + "WHERE {\n"
                + "  {\n"
                + "    SELECT ?s ?p ?o ?cert ?certDiv WHERE {\n"
                + "      VALUES (?s ?p ?o ?cert ?certDiv) {\n"
                + "        (person:alice foaf:knows person:bob \"1.0\"^^xsd:decimal 0 )\n"
                + "        (person:alice foaf:knows person:carol \"0.3\"^^xsd:decimal \"0.1\"^^xsd:decimal)\n"
                + "        (person:carol foaf:knows person:mike \"0.7\"^^xsd:decimal \"0.2\"^^xsd:decimal)\n"
                + "        (person:mike foaf:knows person:carol \"0.1\"^^xsd:decimal UNDEF)\n"
                + "        (person:bob foaf:knows person:carol \"0.8\"^^xsd:decimal UNDEF)\n"
                + "        (person:alice foaf:knows person:mike \"0.6\"^^xsd:decimal \"0.1\"^^xsd:decimal)\n"
                + "        (person:alice foaf:member org:W3C UNDEF UNDEF)\n"
                + "        (person:mike foaf:member org:W3C UNDEF UNDEF)\n"
                + "        (person:alice rdf:type foaf:Person UNDEF UNDEF)\n"
                + "        (person:carol rdf:type foaf:Person UNDEF UNDEF)\n"
                + "        (person:mike rdf:type foaf:Person UNDEF UNDEF)\n"
                + "        (person:bob rdf:type foaf:Person UNDEF UNDEF)\n"
                + "        (org:W3C rdf:type foaf:Organization UNDEF UNDEF)\n"
                + "        (person:alice rdfs:label \"Alice\" UNDEF UNDEF)\n"
                + "        (person:alice foaf:birthday \"1990-01-01\" UNDEF UNDEF)\n"
                + "        (person:bob rdfs:label \"Bob\" UNDEF UNDEF)\n"
                + "        (person:carol rdfs:label \"Carol\" UNDEF UNDEF)\n"
                + "        (person:mike rdfs:label \"Mike\" UNDEF UNDEF)\n"
                + "      }\n"
                + "    }\n"
                + "  }\n"
                + "}";
        // @formatter:on

        Repository repo = new SailRepository(new MemoryStore());
        try (RepositoryConnection con = repo.getConnection()) {
            GraphQuery graphQuery = con.prepareGraphQuery(queryString);
            try (GraphQueryResult result = graphQuery.evaluate()) {
                while (result.hasNext()) { // iterate over the result
                    Statement stmt = result.next();
                    System.out.println(stmt);
                }
            }
        }
        catch (IllegalArgumentException e) {
            e.printStackTrace();
            fail("Should not get an IllegalArgumentException!");
        }
    }
}

Version

4.1.0

Are you interested in contributing a solution yourself?

No response

Anything else?

No response

@jetztgradnet jetztgradnet added the 🐞 bug issue is a bug label Aug 9, 2022
@hmottestad hmottestad added this to the 4.1.1 milestone Aug 10, 2022
hmottestad added a commit that referenced this issue Aug 17, 2022
hmottestad added a commit that referenced this issue Aug 17, 2022
hmottestad added a commit that referenced this issue Aug 17, 2022
…at we don't accidently share one Var object between multiple tuple expressions
hmottestad added a commit that referenced this issue Aug 18, 2022
hmottestad added a commit that referenced this issue Aug 18, 2022
GH-4112 fix query regression for CONSTRUCT query with RDF*
@jetztgradnet
Copy link
Author

Thanks for fixing this, @hmottestad!
Is there a planned release time for 4.1.1?

@hmottestad
Copy link
Contributor

We do not have a planned date yet.

@hmottestad
Copy link
Contributor

@jetztgradnet I've just now released 4.1.1.

@jetztgradnet
Copy link
Author

@hmottestad thanks for the notification (and the bugfix!), we'll update shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug issue is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants