[Mulgara-general] SPARQL question

Alex Hall alexhall at revelytix.com
Tue Dec 2 15:46:59 UTC 2008


Paul Gearon wrote:
>> In a more general sense, I don't really understand the difference between "raw"
>> and "filtered" column values.  It seems that filtering should be applied on a
>> row-by-row basis, not a column-by-column basis.  LeftJoin appears to be the only
>> class that is evaluating these differently.  I would think that if the
>> right-hand side of an optional join is filtered out in normal evaluation, then
>> it's not valid for filters outside the join to ever access the values that it
>> would have been bound to.  Paul, am I incorrect?  My instinct is that the inner
>> filter should be pushed down into the right-hand-side of the optional join, not
>> evaluated as part of the join itself.
> 
> Ah, you'd THINK that, wouldn't you?  That's what *I* thought as well.
> However, read:
>   http://www.w3.org/TR/rdf-sparql-query/#convertGraphPattern
> This describes the transformation sequence needed to evaluate SPARQL.
> Initially I thought I could use the TQL query engine as it was, but it
> kept missing corner cases. It wasn't until I followed this
> transformation sequence carefully (including filtered joins) that it
> all started to come together.  I thought I could make the filter a
> wrapper around the join, but the semantics are a little different.

Hmm... So as a side effect of all this, suppose that you have a simple RDF graph
with the statements:

<test:x> <rdf:type> <test:A> .
<test:x> <rdf:value> "1" .
<test:x> <rdf:value> "2"

And we execute the SPARQL query:

SELECT ?x ?value
WHERE {
  ?s rdf:type test:A
  OPTIONAL { ?x rdf:value ?value FILTER( ?value != "2" ) }
}

Mulgara gives you an answer with two rows:

?x       ?value
test:x   "1"
test:x   <null>

I *think* those are valid results according to the SPARQL definition, but it
just strikes me as backwards.  Without carefully reading the spec, I would
expect the filter to be applied before the join, and the solution to have only
one row, where ?value is bound to "1".

Oh well, you live and you learn...

Alex



More information about the Mulgara-general mailing list