[Mulgara-general] how to order walk solutions

Greg Jansen count0 at email.unc.edu
Mon Nov 24 14:10:55 UTC 2008


Paul Gearon wrote:
> Hi Greg,
>
> On Fri, Nov 21, 2008 at 8:52 AM, Greg Jansen <count0 at email.unc.edu> wrote:
>   
>> Below I have pasted two queries and their output, note the difference in
>> solution order.  The graph is a simple hierarchy of "contains"
>> predicates.  I'd like to get the solutions back in the same order they
>> are walked.  Is that order lost when you remove walk variables?  Is it
>> sufficient to include just one variable from the walk?
>> Any recommendations are much appreciated.
>>     
>
> TQL (and a a limited extent, SPARQL) operates on set-semantic. This
> means that order has no meaning. That said, it is possible to select a
> variable to order by in the results. For instance, "order by $child".
>
> However, there is no effective way to have a query return data in the
> order that it "walks" a predicate. Not only doesn't it make sense from
> the perspective of set theory, it would also subvert the query
> optimizer.
>
> The only way you can see the natural order that was walked is if the
> WHERE clause contains nothing but the WALK statement. This is because
> the query engine will have no need to re-order the data in order to
> work with it. But the result is treated as a set, so the moment some
> other condition is imposed upon it, then the ordering will be changed
> to whatever is most efficient (hopefully).
>
> So the best I can offer is to suggest a programmatic solution.  You'd
> have to query the data twice, using the queries you gave in your
> examples below. Store the first result in a list, and then convert the
> second result to a map of the "ordering" column (the same data that's
> in your list) to the remaining columns.
>
> Regards,
> Paul
>   
Thanks Paul!  I took your advice and rewrote the operation using two 
queries and a map.
Greg

>   
>> TQL> select $child from <rmi://127.0.0.1/server1#ri>
>> where walk(
>>  $p <http://cdr.unc.edu/definitions/1.0/base-model.xml#contains>
>> <info:fedora/changeme:2556>
>>  and $p <http://cdr.unc.edu/definitions/1.0/base-model.xml#contains> $c)
>> and $c <http://cdr.unc.edu/definitions/1.0/base-model.xml#slug> $child;
>> [ "mencius" ]
>> [ "confucians" ]
>> [ "writings" ]
>> 3 rows returned.
>>
>> TQL> select $child $c from <rmi://127.0.0.1/server1#ri>
>> where walk(
>>  $p <http://cdr.unc.edu/definitions/1.0/base-model.xml#contains>
>> <info:fedora/changeme:2556>
>>  and $p <http://cdr.unc.edu/definitions/1.0/base-model.xml#contains> $c)
>> and $c <http://cdr.unc.edu/definitions/1.0/base-model.xml#slug> $child;
>> [ "confucians", info:fedora/changeme:2554 ]
>> [ "mencius", info:fedora/changeme:2555 ]
>> [ "writings", info:fedora/changeme:2556 ]
>> 3 rows returned.
>>
>>
>> __
>> Greg Jansen
>> Carolina Digital Repository
>> University of North Carolina at Chapel Hill
>> _______________________________________________
>> Mulgara-general mailing list
>> Mulgara-general at mulgara.org
>> http://mulgara.org/mailman/listinfo/mulgara-general
>>
>>     
> _______________________________________________
> Mulgara-general mailing list
> Mulgara-general at mulgara.org
> http://mulgara.org/mailman/listinfo/mulgara-general
>   




More information about the Mulgara-general mailing list