virtuoso-opensource
virtuoso-opensource copied to clipboard
Variable '_::trans_subj_10_0' is used in subexpressions of the query but not assigned
Why does the following simple query fail?
DEFINE sql:signal-void-variables 1
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT *
WHERE {
OPTIONAL {
?t1 rdfs:subClassOf* <a> .
}
OPTIONAL {
?t2 rdfs:subClassOf* <b> .
}
}
The error message is:
Virtuoso 37000 Error SP031: SPARQL compiler: Variable '_::trans_subj_10_0' is used in subexpressions of the query but not assigned
Strangely, it works if I remove either of the two optional blocks, and it also fails without the OPTIONAL:
SELECT *
WHERE {
{
?t1 rdfs:subClassOf* <a> .
}
?t2 rdfs:subClassOf* <b> .
}
Querying from the Virtuoso /sparql endpoint form page, you need to uncheck the "Strict checking of void variables" checkbox option before executing the query to avoid that error message ...
@HughWilliams I know, but I was not sure if I could expect valid results in that case, considering the somewhat cryptical error message. Is this intended?
In fact, it fails because you've told Virtuoso to make a specific check, and fail if that check succeeds based on your data and query.
Simply change DEFINE sql:signal-void-variables 1 in your query to DEFINE sql:signal-void-variables 0, and this error will be eliminated. (This pragma has the same effect as that "Strict checking of void variables" checkbox on Virtuoso's default SPARQL query form.)
This pragma is discussed in some detail at 16.2.4. Troubleshooting SPARQL Queries --
Two very helpful debugging tools are automatic void variable recognition and plain old code inspection. "Automatic" means "cheap" so the very first step of debugging is to ensure that every triple pattern of the query may in principle return something. This helps in finding typos when the query gets data from Linked Data Views. It also helps when a query tries to join two disjoint sorts of subjects. If the
define sql:signal-void-variables 1directive is placed in the preamble of the SPARQL query, the compiler will signal an error if it finds any triple pattern that cannot bind variables or any variable that is proved to be always unbound. This is especially useful when data are supposed to come from anoption (exclusive)oroption (soft exclusive)quad map. Without one of these options, the SPARQL compiler will usually bind variables using "physical quads"; the table of physical quads may contain any rows that match any given triple pattern; thus many errors will remain undiscovered.
-- and in the Pragmas to control code generation section of 16.2.12. Supported SPARQL-BI "define" pragmas --
sql:signal-void-variables: the most useful debugging variable if Linked Data Views are in use. It tells the SPARQL compiler to signal an error if it can prove that some variable can never be bound. Usually it means error in query, like typo in IRI or totally wrong triple pattern.
The cryptic error message is built based on the SQL translation and execution plan for the SPARQL query. This is discussed in some detail here.
I hope this is helpful.