virtuoso-opensource icon indicating copy to clipboard operation
virtuoso-opensource copied to clipboard

Blank nodes not allowed with SPARQL 1.1. `INSERT DATA`?

Open jakubklimek opened this issue 12 years ago • 28 comments

INSERT DATA {_:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> """67401""" .}

results in SP031: SPARQL compiler: Blank node '_:node18errd605x19406' is not allowed in a constant clause

INSERT {_:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> """67401""" .}
is OK.

However, in the SPARQL 1.1 INSERT DATA specification I don't see any reason why this should be disallowed. The same states this answer

jakubklimek avatar Jan 22 '14 09:01 jakubklimek

This problem has been recreated and reported to development to look into ...

HughWilliams avatar Jan 26 '14 15:01 HughWilliams

There is a similar issue with DELETE, for which I found Can I Delete Triples containing Blank Nodes?, but I'm trying to write an adapter that will need to be able to address specific identifiers, blank or otherwise, without any prior knowledge of their contents other than what has been previously returned from the server.

Blank nodes come out of Virtuoso with identifiers of the style nodeID://123456, but I'd like to know if: a) that is a deterministic relationship to the internal representation; and b) how stable it is.

(P.S. That nodeID::// formulation breaks parsers expecting the Turtle syntax for bnodes. Even _:123456 would be valid. Is there any way to change it?)

doriantaylor avatar Mar 13 '14 21:03 doriantaylor

Never mind, found this section of the manual: 16.1. Data Representation

Plus this solution:

SELECT
    ( <LONG::bif:iri_id_num> ( ?s ) ) AS ?s_num
    ( <LONG::bif:iri_id_num> ( <LONG::bif:min_64bit_bnode_iri_id> ( ) ) ) AS ?min
    ?s ?p ?o
WHERE {
    GRAPH <http://example.com/d> {
        ?s ?p ?o 
        FILTER isBLANK(?s)
    }
}

Presumably I'll be able to massage something out of that.

doriantaylor avatar Mar 13 '14 22:03 doriantaylor

Oops, never mind. Found that nodeID://b123456 can be addressed as a skolem IRI.

doriantaylor avatar Mar 13 '14 22:03 doriantaylor

I could also reproduce the problem.

@HughWilliams: Any words on when will this issue be fixed? Is it at least planed?

@jakubklimek: I found a workaround (version: same as here). Instead of this:

INSERT DATA 
    { _:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> """67401""" . }

try this

INSERT 
  { GRAPH <urn:test> 
    { _:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .}
  } 
WHERE
  { SELECT * 
    { OPTIONAL {?s ?p ?o} } 
LIMIT 1 }

really ugly, but useful if you absolutely need to import blank nodes using the SPARQL interface.

rnavarropiris avatar Dec 09 '14 16:12 rnavarropiris

What version have you tested against as your workaround query failed for me against the latest git develop/7 branch ?

SPARQL INSERT DATA {_:node18errd605x19406 http://www.w3.org/2006/vcard/ns#postalCode """67401""" .}
SQL> SPARQL INSERT {_:node18errd605x19406 http://www.w3.org/2006/vcard/ns#postalCode """67401""" .} WHERE { SELECT \* {OPTIONAL {?s ?p ?o} } LIMIT 1 };

**\* Error 37000: VD [Virtuoso Server]SQ074: Line 1: SP031: SPARQL compiler: No default graph specified in the preamble, but it is needed for triple constructor in INSERT {...} without GRAPH {...}
at line 3 of Top-Level:
SPARQL INSERT {_:node18errd605x19406 http://www.w3.org/2006/vcard/ns#postalCode """67401""" .} WHERE { SELECT \* {OPTIONAL {?s ?p ?o} } LIMIT 1 }
SQL> 

Thus I needed to specify and actual default graph name as indicated, for it to work:

SQL> SPARQL INSERT { GRAPH <test> {_:node18errd605x19406 http://www.w3.org/2006/vcard/ns#postalCode """67401""" . } } WHERE { SELECT \* {OPTIONAL {?s ?p ?o} } LIMIT 1 };

Done. -- 1 msec.
SQL> 

HughWilliams avatar Dec 14 '14 00:12 HughWilliams

@HughWilliams my bad, I copied a wrong version of the query. I updated my previous comment with a corrected one. The version I used is the same as here).

rnavarropiris avatar Dec 15 '14 09:12 rnavarropiris

@rnavarropiris , the updated variant of the query runs for me now:

SQL> SPARQL INSERT {GRAPH urn:test {_:node18errd605x19406 http://www.w3.org/2006/vcard/ns#postalCode "67401" .}} WHERE { SELECT \* {OPTIONAL {?s ?p ?o} } LIMIT 1 };

Done. -- 222 msec.
SQL> SPARQL select \* from urn:test where {?s ?p ?o };
s                                                                                 p                                                                                 o
VARCHAR                                                                           VARCHAR                                                                           VARCHAR

---

nodeID://b10013                                                                   http://www.w3.org/2006/vcard/ns#postalCode                                        67401

1 Rows. -- 27 msec.
SQL> 

HughWilliams avatar Dec 21 '14 02:12 HughWilliams

The next versions of INSERT are worked for me:

SPARQL INSERT INTO <urn:test> {_:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .}; 
SPARQL INSERT {GRAPH <urn:test> {_:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .}};

It isn't used INSERT DATA... query, but it works. About deleting of Blank Nodes like: nodeID://b12345 The next queries are worked properly:

sparql DELETE FROM <urn:test> { <nodeID://b12345>  <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .};

OR

sparql DELETE FROM <urn:test> { `iri("nodeID://b12345")` <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .};

smalinin avatar Dec 22 '14 05:12 smalinin

@smalinin: in your examples, neither the used syntax nor the direct usage of a node id are compliant with SPARQL 1.1 (which is a requirement of my current use case), that is why I use the mentioned "ugly" query workaround (it works with Virtuoso & Jena in-memory model, should work with other SPARQL 1.1 compliant stores as well)

rnavarropiris avatar Dec 29 '14 16:12 rnavarropiris

@HughWilliams I think that INSERT DATA should handle these kind of bnodes (do you know if this will happen?)

However,

@rnavarropiris are you saying that:

SPARQL INSERT {GRAPH <urn:test> {_:node18errd605x19406 <http://www.w3.org/2006/vcard/ns#postalCode> "67401" .}};

is not SPARQL 1.1 compliant? If so, in what it is not?

fgiasson avatar Jan 20 '15 15:01 fgiasson

@fgiasson: yes, the query is not compliant with the 2 INSERT query types: INSERT/DELETE (missing where clause) or INSERT DATA (missing DATA keyword). Virtuoso, however, accepts the "wrong" query (be it for backwards compatibility or for any other reason)

rnavarropiris avatar Jan 20 '15 15:01 rnavarropiris

@rnavarropiris yeah that is right, didn't noticed the missing where clause. I think this is for backwards compatibility when the SPARUL specification was around (before SPARQL Update 1.1)

fgiasson avatar Jan 20 '15 15:01 fgiasson

@fgiasson: I am checking the status of this with development ...

HughWilliams avatar Jan 21 '15 11:01 HughWilliams

@HughWilliams: what's the status of this issue?

rnavarropiris avatar Jan 04 '16 10:01 rnavarropiris

@rnavarropiris: It is still not resolved ...

HughWilliams avatar Jan 10 '16 14:01 HughWilliams

Our integration tests [0] just encountered a similar issue:

PREFIX wiki: <http://example.org/id/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX swivt: <http://semantic-mediawiki.org/swivt/1.0#>
PREFIX property: <http://example.org/id/Property-3A>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX category: <http://example.org/id/Category-3A>
PREFIX wikiurl: <http://localhost/TravisWiki/index.php/>
INSERT DATA INTO GRAPH <http://example.org/phpunit-testrun> { 
wiki:Concept-3AConcept_for_any_value_selection
    rdf:type  owl:Class ;
    rdfs:label  "Concept for any value selection" ;
    swivt:page  <http://localhost/TravisWiki/index.php/Concept:Concept_for_any_value_selection> ;
    rdfs:isDefinedBy  <http://localhost/TravisWiki/index.php/Special:ExportRDF/Concept:Concept_for_any_value_selection> ;
    swivt:wikiNamespace  "108"^^xsd:integer ;
    owl:intersectionOf  (       [   rdf:type  owl:Restriction ;
            owl:onProperty  property:Population ;
            owl:someValuesFrom  rdfs:Literal ]      [   rdf:type  owl:Restriction ;
            owl:onProperty  property:Has_concept_description ;
            owl:someValuesFrom  rdfs:Literal ] ) ;
    swivt:wikiPageModificationDate  "2016-03-12T12:49:51Z"^^xsd:dateTime ;
    property:Modification_date-23aux  "2457460.0346181"^^xsd:double ;
    swivt:wikiPageSortKey  "Concept for any value selection" .
property:Modification_date
    rdf:type  owl:ObjectProperty ;
    rdfs:label  "Modification date" ;
    swivt:page  <http://localhost/TravisWiki/index.php/Property:Modification_date> ;
    rdfs:isDefinedBy  <http://localhost/TravisWiki/index.php/Special:ExportRDF/Property:Modification_date> ;
    swivt:wikiNamespace  "102"^^xsd:integer ;
    swivt:wikiPageSortKey  "Modification date" .
<http://semantic-mediawiki.org/swivt/1.0#page> rdf:type owl:ObjectProperty .
<http://semantic-mediawiki.org/swivt/1.0#wikiNamespace> rdf:type owl:DatatypeProperty .
<http://semantic-mediawiki.org/swivt/1.0#wikiPageModificationDate> rdf:type owl:DatatypeProperty .
<http://example.org/id/Property-3AModification_date-23aux> rdf:type owl:DatatypeProperty .
<http://semantic-mediawiki.org/swivt/1.0#wikiPageSortKey> rdf:type owl:DatatypeProperty .
 }

returns with

Virtuoso 37000 Error SP031: SPARQL compiler: Blank node '_:topcons_19_11' is not allowed in a constant clause

SPARQL query:
define sql:big-data-const 0 

Yet, the query works successful on Fuseki 1.1.1 [1], Sesame 2.8.7, and Blazegraph 1.5.2 [3].

[0] https://travis-ci.org/SemanticMediaWiki/SemanticMediaWiki/jobs/115515265 [1] https://travis-ci.org/SemanticMediaWiki/SemanticMediaWiki/jobs/115515263 [2] https://travis-ci.org/SemanticMediaWiki/SemanticMediaWiki/jobs/115515269 [3] https://travis-ci.org/SemanticMediaWiki/SemanticMediaWiki/jobs/115515272

mwjames avatar Mar 12 '16 13:03 mwjames

@mwjames: This test case has been added to the internal ticket for development to look into ...

HughWilliams avatar Mar 16 '16 01:03 HughWilliams

On 3/15/16 9:32 PM, HughWilliams wrote:

@mwjames https://github.com/mwjames: This test case has been added to the internal ticket for development to look into ...

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/openlink/virtuoso-opensource/issues/126#issuecomment-197101207

This issue is scheduled to be fixed such that SPARQL 1.1 INSERT variations work consistently.

Regards,

Kingsley Idehen

kidehen avatar Mar 16 '16 17:03 kidehen

@kidehen Scheduled for a specific date/version? (7.2.5? 7.3.x?)

rnavarropiris avatar Jul 06 '16 16:07 rnavarropiris