[MonetDB-users] MonetDB/XQuery order by problem
Hello, I'm trying to produce a sorted list of results with MonetDB/XQuery using 'order by', with a query that goes something like this: for $cname in pf:collections()/text() return if (local:is-date-between($cname, **start_date_here**, **end_date_here**)) then for $s in pf:collection($cname)//Dublin/stations[time/hour=13 and time/minute>=22 and time/minute<=25] order by $s/timeOfDay return $s else () ...the 'is-date-between' is just some custom function to check if the $cname (collection names are dates) is between the start and end dates supplied to the function. However, the problem is with the nested for loop. I want each $s that satisfies the XPath expression to be returned, but ordered by $s/timeOfDay. When I submit this query, I get the following error: ERROR = !type error: [err:XPTY0004] Orderspec requires at most one atomic item (given: string*). I've tried a number of variations on this, but the error is always the same. If I remove the order by clause, the results will return correctly, but in the unsorted order that they appear in the database. I'm still a beginner with XQuery, so I'm unsure where I'm going wrong, and documentation and tutorials have been unhelpful so far. Any help is appreciated! Regards, -Rob
Hi Rob, you can wrap '$s/timeOfDay' with a call to function 'zero-or-one()' or 'exactly-one()' (depending on what you know about your data). Then it will check at runtime (instead of at compile time) for the correctness of your query. Regards, Jan On Mar 12, 2011, at 20:10, Rob Fynes wrote:
Hello,
I'm trying to produce a sorted list of results with MonetDB/XQuery using 'order by', with a query that goes something like this:
for $cname in pf:collections()/text() return if (local:is-date-between($cname, **start_date_here**, **end_date_here**)) then for $s in pf:collection($cname)//Dublin/stations[time/hour=13 and time/minute>=22 and time/minute<=25] order by $s/timeOfDay return $s else ()
...the 'is-date-between' is just some custom function to check if the $cname (collection names are dates) is between the start and end dates supplied to the function. However, the problem is with the nested for loop. I want each $s that satisfies the XPath expression to be returned, but ordered by $s/timeOfDay.
When I submit this query, I get the following error: ERROR = !type error: [err:XPTY0004] Orderspec requires at most one atomic item (given: string*).
I've tried a number of variations on this, but the error is always the same. If I remove the order by clause, the results will return correctly, but in the unsorted order that they appear in the database.
I'm still a beginner with XQuery, so I'm unsure where I'm going wrong, and documentation and tutorials have been unhelpful so far. Any help is appreciated!
Regards, -Rob ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d__________________________________________... MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Jan Rittinger Lehrstuhl Datenbanken und Informationssysteme Wilhelm-Schickard-Institut für Informatik Eberhard-Karls-Universität Tübingen http://www-db.informatik.uni-tuebingen.de/team/rittinger
Hi Jan, Thanks for the reply. I tried as you suggested, but when I try the 'order by' clause with 'zero-or-one($s/timeOfDay)' or ''exactly-one($s/timeOfDay)', the query does compile and run, but without sorting the results. I gather that these functions are checking if $s/timeOfDay contains zero-or-one and exactly-one item(s), respectively, and that they are returning nothing?, and so the order by clause does no ordering. However, this particular node that I wish to sort by (timeOfDay) contains no child nodes, only a single time and date string. My understanding is that by iterating through each of the 'stations' nodes using the nested for loop, the results should be ordered based on the 'timeOfDay' value of each 'stations' node. Here's a snippet of the data for one 'stations' node: <stations> <time> <hour>08</hour> <minute>34</minute> <second>50</second> </time> <timeOfDay>08:34:50 01-06-2010</timeOfDay> <timeUnit>milliseconds</timeUnit> <timeStart>1275377690000</timeStart> ..... ..... Regards, -Rob On Sat, Mar 12, 2011 at 8:03 PM, Jan Rittinger < jan.rittinger@uni-tuebingen.de> wrote:
Hi Rob,
you can wrap '$s/timeOfDay' with a call to function 'zero-or-one()' or 'exactly-one()' (depending on what you know about your data). Then it will check at runtime (instead of at compile time) for the correctness of your query.
Regards, Jan
On Mar 12, 2011, at 20:10, Rob Fynes wrote:
Hello,
I'm trying to produce a sorted list of results with MonetDB/XQuery using 'order by', with a query that goes something like this:
for $cname in pf:collections()/text() return if (local:is-date-between($cname, **start_date_here**, **end_date_here**)) then for $s in pf:collection($cname)//Dublin/stations[time/hour=13 and time/minute>=22 and time/minute<=25] order by $s/timeOfDay return $s else ()
...the 'is-date-between' is just some custom function to check if the $cname (collection names are dates) is between the start and end dates supplied to the function. However, the problem is with the nested for loop. I want each $s that satisfies the XPath expression to be returned, but ordered by $s/timeOfDay.
When I submit this query, I get the following error: ERROR = !type error: [err:XPTY0004] Orderspec requires at most one atomic item (given: string*).
I've tried a number of variations on this, but the error is always the same. If I remove the order by clause, the results will return correctly, but in the unsorted order that they appear in the database.
I'm still a beginner with XQuery, so I'm unsure where I'm going wrong, and documentation and tutorials have been unhelpful so far. Any help is appreciated!
Regards, -Rob
------------------------------------------------------------------------------
Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future.
http://p.sf.net/sfu/internap-sfd2d__________________________________________...
MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Jan Rittinger Lehrstuhl Datenbanken und Informationssysteme Wilhelm-Schickard-Institut für Informatik Eberhard-Karls-Universität Tübingen
http://www-db.informatik.uni-tuebingen.de/team/rittinger
------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
Hi Rob, zero-or-one() and exactly-one() behave as described in http://www.w3.org/TR/xquery-operators/#cardinality-functions. Your understanding with respect to the query also sounds correct. One thing you might think about is, that the ORDER BY clause in your query compares the dates as strings. If you want to compare them as xs:dateTime values you might add a cast ('order by xs:dateTime (exactly-one ($s/timeOfDay))'). I only see a problem with your time format in the example below (c.f. 'xs:dateTime("2010-06-01T08:34:50")'). Regards, Jan On Mar 12, 2011, at 21:47, Rob Fynes wrote:
Hi Jan,
Thanks for the reply. I tried as you suggested, but when I try the 'order by' clause with 'zero-or-one($s/timeOfDay)' or ''exactly-one($s/timeOfDay)', the query does compile and run, but without sorting the results.
I gather that these functions are checking if $s/timeOfDay contains zero-or-one and exactly-one item(s), respectively, and that they are returning nothing?, and so the order by clause does no ordering. However, this particular node that I wish to sort by (timeOfDay) contains no child nodes, only a single time and date string. My understanding is that by iterating through each of the 'stations' nodes using the nested for loop, the results should be ordered based on the 'timeOfDay' value of each 'stations' node.
Here's a snippet of the data for one 'stations' node:
<stations> <time> <hour>08</hour> <minute>34</minute> <second>50</second> </time> <timeOfDay>08:34:50 01-06-2010</timeOfDay> <timeUnit>milliseconds</timeUnit> <timeStart>1275377690000</timeStart> ..... .....
Regards, -Rob
On Sat, Mar 12, 2011 at 8:03 PM, Jan Rittinger
wrote: Hi Rob, you can wrap '$s/timeOfDay' with a call to function 'zero-or-one()' or 'exactly-one()' (depending on what you know about your data). Then it will check at runtime (instead of at compile time) for the correctness of your query.
Regards, Jan
On Mar 12, 2011, at 20:10, Rob Fynes wrote:
Hello,
I'm trying to produce a sorted list of results with MonetDB/XQuery using 'order by', with a query that goes something like this:
for $cname in pf:collections()/text() return if (local:is-date-between($cname, **start_date_here**, **end_date_here**)) then for $s in pf:collection($cname)//Dublin/stations[time/hour=13 and time/minute>=22 and time/minute<=25] order by $s/timeOfDay return $s else ()
...the 'is-date-between' is just some custom function to check if the $cname (collection names are dates) is between the start and end dates supplied to the function. However, the problem is with the nested for loop. I want each $s that satisfies the XPath expression to be returned, but ordered by $s/timeOfDay.
When I submit this query, I get the following error: ERROR = !type error: [err:XPTY0004] Orderspec requires at most one atomic item (given: string*).
I've tried a number of variations on this, but the error is always the same. If I remove the order by clause, the results will return correctly, but in the unsorted order that they appear in the database.
I'm still a beginner with XQuery, so I'm unsure where I'm going wrong, and documentation and tutorials have been unhelpful so far. Any help is appreciated!
Regards, -Rob ------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d__________________________________________... MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Jan Rittinger Lehrstuhl Datenbanken und Informationssysteme Wilhelm-Schickard-Institut für Informatik Eberhard-Karls-Universität Tübingen
http://www-db.informatik.uni-tuebingen.de/team/rittinger
------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d _______________________________________________ MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
------------------------------------------------------------------------------ Colocation vs. Managed Hosting A question and answer guide to determining the best fit for your organization - today and in the future. http://p.sf.net/sfu/internap-sfd2d__________________________________________... MonetDB-users mailing list MonetDB-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/monetdb-users
-- Jan Rittinger Lehrstuhl Datenbanken und Informationssysteme Wilhelm-Schickard-Institut für Informatik Eberhard-Karls-Universität Tübingen http://www-db.informatik.uni-tuebingen.de/team/rittinger
participants (2)
-
Jan Rittinger
-
Rob Fynes