- From: Eric Prud'hommeaux <eric@w3.org>
- Date: Fri, 8 Sep 2006 14:28:11 +0200
- To: Dave Beckett <dave@dajobe.org>
- Cc: public-rdf-dawg-comments@w3.org
On Sat, Jul 01, 2006 at 04:03:19PM -0700, Dave Beckett wrote:
>
> I was looking for the references that told me what to do when an
> unbound variable appears in a FILTER expression but I've been having
> trouble with locating them. Maybe you can point me at the right
> places.
In 1.20, I took a conservative approach and added
<li>Apart from <a href="#func-bound">BOUND</a>, all functions and operators operate on RDF Terms and will produce a type error if any arguments are unbound.</li>
to 11.2 Filter Evaluation [EVAL] and
<li>All other arguments, including unbound arguments, produce a type error.</li>
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
to 11.2.2 Effective Boolean Value. This has not been approved by the DAWG.
This represents a potential curtailment of extensibility in that
extensions may not see the variable name or anything else about a
variable. I think this is reasonable for this version of SPARQL.
Looking at your test cases, I believe this wording addresses them.
[EVAL] http://www.w3.org/2001/sw/DataAccess/rq23/rq24#evaluation
[EBV] http://www.w3.org/2001/sw/DataAccess/rq23/rq24#ebv
> RDF Data (data.rdf) - the empty graph:
> <?xml version="1.0"?>
> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
> </rdf:RDF>
>
>
> Query 1: optional test
> PREFIX ex: <http://example.org/>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> }
>
> The answer to this is a well defined result set with 1 answer:
> ?s=unbound
>
>
> Query 2: BOUND test
> PREFIX ex: <http://example.org/>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> FILTER BOUND(?s)
> }
>
> This also has well defined answer - the empty result set - since
> BOUND takes a variable type argument and can check for variable
> boundness.
>
>
> Query 3: unbound variable
> PREFIX ex: <http://example.org/>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> FILTER (?s)
> }
>
> What result should this give?
EBV of unbound now a type error
> My analysis: ?s is evaluated acording to Sec 11: Testing Values
> http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#tests
> which describes this as evaluating an expression; here that is ?s
> it says:
> [[FILTERs eliminate any solutions that, when substituted into the
> expression, result in either an effective boolean value of false or
> produce an error. ]]
>
> Does ?s with no binding for s evaluate to false or error?
> Is this a type error or another kind of error?
>
> I couldn't find a section in the document to answer this.
>
> The result set is the same in either case here but may not in other
> cases. If the result is error, it may allow shortcutting some
> expression evaluation since the error value will propogate e.g
> in arithmetic expressions like
> ?s / foo:bar(....)
> where foo:bar is something expensive to compute
> it need not be evaluated if ?s returns an error
(my usual example of this breaking is by putting not (!) around it)
> Query 4: unbound variable in expression evaluation
> PREFIX ex: <http://example.org/>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> FILTER (?s = FALSE)
> }
Also covered by EBV
> Depending on the answer to the question above, this filter expression
> will return Error if unbound ?s evaluates to Error or True if unbound
> ?s evaluates to False.
>
> Which means different numbers of results will be given, either none or 1.
> So this query is a test for how current implementations evaluate
> this.
>
> My reasoning for this is based on the T,F,E table in
> http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#evaluation
> and
> [[Any expression other than logical or (||) or logical and (&&) that
> encounters an error will produce that error. ]]
> -- ibid
> which applies here to the equal(=) function.
>
>
> Can you pass an unbound variable to an (extension) function? I'm
> guessing not since
> http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#extensionFunctions
> says the arguments are RDF terms.
>
>
> Query 5: unbound variable in an extension function
> PREFIX ex: <http://example.org/>
> PREFIX foo: <http://example.org/foo#>
>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> FILTER foo:bar(?s)
> }
is not the BOUND operator so now a type error
> What does this return?
>
> Does it do this without evaluating the extension function?
>
>
> This issue applies to Constructor Functions evaluating over undefined
> variables, which are defined in a different section:
> http://www.w3.org/TR/2006/CR-rdf-sparql-query-20060406/#FunctionMapping
>
>
> Query 6: unbound variable in constructor function
>
> PREFIX ex: <http://example.org/>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
>
> SELECT ?s
> FROM <data.rdf>
> WHERE {
> OPTIONAL { ex:a ex:b ?s }
> FILTER (xsd:decimal(?s) = 0)
> }
ditto
> What does this return?
>
> (using casting defined in
> http://www.w3.org/TR/xpath-functions/#casting-to-numerics
> )
>
> ---
>
> While checking these I found ARQ evaluates unbound ?s to Error, not
> False so that the answers to queries 3-6 are all the empty set. I
> didn't test query 5 without having an extension function handy to use.
>
> Dave
--
-eric
home-office: +1.617.395.1213 (usually 900-2300 CET)
+33.1.45.35.62.14
cell: +33.6.73.84.87.26
(eric@w3.org)
Feel free to forward this message to any list for any purpose other than
email address distribution.
Received on Friday, 8 September 2006 12:27:08 UTC