RE: [sub-select] Some examples and discussion



> -----Original Message-----
> From: public-rdf-dawg-request@w3.org [mailto:public-rdf-dawg-
> request@w3.org] On Behalf Of Steve Harris
> Sent: 12 March 2009 10:33
> To: SPARQL Working Group
> Subject: Re: [sub-select] Some examples and discussion
> 
> On 12 Mar 2009, at 06:39, Lee Feigenbaum wrote:
> > The idea of using ASK queries in expressions appeals to me as well,
> > though it doesn't necessarily read as well as !EXISTS in SQL. The
> > verbosity is similar though, I guess.
> 
> Similar, and it's one less bit of syntax. My personal preference is
> for fewer, more flexible verbs. But it's just a matter of taste.
> 
> > I'm curious as to the interplay between:
> >
> > projected expressions
> > sub-selects
> > assignment
> >
> > Is there a combination of these that makes the 3rd irrelevant? Or
> > pairs of them that are far more useful when included together?
> > That's the sort of thing I'm working to wrap my head around.
> 
> Yes, if you have projected expressions then you effectively get
> assignments:
> 
>     SELECT ?x
>     WHERE {
>        ?x :age ?age .
>        FILTER(?age >= ?min_age)
>        (SELECT 18 AS ?min_age)
>     }
> 
> Is equivalent to:
> 
>     SELECT ?x
>     WHERE {
>        ?x :age ?age .
>        FILTER(?age >= ?min_age)
>        LET(?min_age := 18)
>     }

Steve - good example because it's different and a bit more tricky.  Let (err - no pun intended) me work though the details.  This is a more tricky example than the one I gave because syntactically you assign after the use of ?min_age in the FILTER which raises the necessary question of scope and order.

SELECT ?name ?inch
{
    ?x foaf:name ?name .
    ?x :height ?cm .
    LET ( ?inch := ?cm/2.54 )
    FILTER (?inch > 68)
}

My example was chosen so that the rewrite was nesting: the LET (assign) over pattern P is SELECT (assign) { P }.

SELECT ?name ?inch
{
   { SELECT ?name ( ?cm/2.54 AS ?inch )
     {
       ?x foaf:name ?name .
       ?x :height ?cm .
     }
   }
   FILTER (?inch > 68)
}

The choice of BGP-Assign-FILTER (modelled after the current SPARQL BGP-Filter that happens translating query string to algebra) was to keep things simple and let assignments be visible in the filter.

In your example I can see ~two possibilities: we have ?min_age used in the filter before the (SELECT) assignment.  How do things combine in group?  Up to now it's a join.  It gets the right answer, via a different route.  Suppose the (SELECT) has a variable ?age - by scoping, it's a different ?age, right?

SELECT ?x
    WHERE {
       ?x :age ?age .
       FILTER(?age >= ?min_age)
       (SELECT 18 AS ?min_age)
    }

Possibility 1:
   (join 
       ( ?x :age ?age . FILTER(?age >= ?min_age) )
       (SELECT 18 AS ?min_age)
     )

(But is the scoping right?)

Or 
 (SELECT 18 AS ?min_age), that is, no pattern, is an assignment 
But to make your query work, the assignment must be executed before the filter.


Possibility 2:
Or does the conversion to algebra reorder to

    ?x :age ?age .
    Then assign
    Then FILTER(?age >= ?min_age) )

This is how it might be specified - the optimizer can do sensible things with that later


To everyone:

What do other systems already do?
What do application writers think?
  What principles should matter most in practice?  

 Andy

Received on Thursday, 12 March 2009 13:45:03 UTC