Wow!  I'm new to functional thinking and I can't quite imagine that :)  but am 
looking forward to coming back to this question in a year's time and redoing it

From: David Ennis <david.en...@hinttech.com<mailto:david.en...@hinttech.com>>
Reply-To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Date: Thursday, 2 October 2014 17:50
To: MarkLogic Developer Discussion 
<general@developer.marklogic.com<mailto:general@developer.marklogic.com>>
Subject: Re: [MarkLogic Dev General] order by clause ignored?

HI.

For the sample given, you can also just pack it all in a single sequence where 
the odd numbered indexes are the content dates and the even numbered indexes 
are the dates.

Then a few of the sequence related access functions
Iteration is then just done on the odd numbers, etc,.

If you use the FunctX library, then you already have a toolbox of neat things 
like finding out the position of document 'XYZ', etc

KInd Regards,
David




Kind Regards,
David Ennis


David Ennis
Content Engineer

[HintTech] <http://www.hinttech.com/>
Mastering the value of content
creative | technology | content

Delftechpark 37i
2628 XJ Delft
The Netherlands
T: +31 88 268 25 00
M: +31 63 091 72 80

[http://www.hinttech.com]<http://www.hinttech.com> 
[http://www.hinttech.com/signature/Twitter_HintTech.png] 
<https://twitter.com/HintTech>  
[http://www.hinttech.com/signature/Facebook_HintTech.png] 
<http://www.facebook.com/HintTech>  
[http://www.hinttech.com/signature/Linkedin_HintTech.png] 
<http://www.linkedin.com/company/HintTech>

On 2 October 2014 18:42, Michael Blakeley 
<m...@blakeley.com<mailto:m...@blakeley.com>> wrote:
The order of operations in a FLWOR isn't guaranteed. The return expression 
could be evaluated before the sorting is done.

You might also be interested to know that maps are unordered. So you can put 
those items into the map in any order you like, but the keys will end up in 
whatever internal order the map uses. That should be consistent, but won't be 
under your control.

As an alternative you can order the keys when processing the map. Or consider 
using json:object instead. That's like a map but has an ordered sequence of 
keys.

-- Mike

On 2 Oct 2014, at 09:17 , Rachel Wilson 
<rachel.wil...@bbc.co.uk<mailto:rachel.wil...@bbc.co.uk>> wrote:

> I realise this is more of an xquery question but everyone here is stumped :-s
>
> I have a query that is trying to calculate some earliest and latest dates 
> that an event occurred.  The events are represented in xml like this:
>
> <publication>
>   <publicationDateTime>2013-08-14T15:06:51.921302Z</publicationDateTime>
>   <documents>
>     <document>
>         <id>b119c2a3-5436-59d2-9771-a67f8e2b4172</id>
>         <version>1</version>
>     </document>
> </documents>
> </publication>
>
> There are two events for the this particular document (i.e. with the same 
> document id), and therefore two publication documents on different days.  In 
> order to work out the first and last dates I'm sorting all my publication 
> docs by publication date, then taking the sorted publication documents in 
> order I'm iterating through the publication document ids in order and 
> remembering them in the correct maps for earliest seen and latest seen dates. 
>  However the results in the map are as if the publication documents are 
> coming out in document order.
>
> If I run this query the document dates are coming out in the right order as 
> I'd expect:
> ------------------------------------------------------------------
> let $earliestPubDates := map:map()
> let $latestPubDates := map:map()
> let $buildMaps :=
>    for $x in doc()/publication
>    let $publishedDate := $x/publicationDateTime/string()
>    let $documents := $x/documents/document
>    order by $x/publicationDateTime
>    return
>      (: map building stuff commented out in order to see how the dates are 
> being ordered :)
>      $publishedDate
>
> return $buildMaps
> ---------------------------------------------------------------------
> returns:
> 2013-08-14T15:06:51.921302Z
> 2014-09-03T14:46:07.757612Z
>
>
>
> However, after someone showed me how to debug the loop a little with an error 
> statement, I'm finding that the first publication processed is the later one, 
> not the earlier one.  It looks like the order by in this case is being 
> ignored.  Could someone tell me how and why?
>
>
>
> ----------------------------------------------------------------------------
> let $earliestPubDates := map:map()
> let $latestPubDates := map:map()
>
> let $buildMaps :=
>    for $x in doc()/publication
>    let $documents := $x/documents/document
>    order by $x/publicationDateTime
>    return
>       for $contentId in $documents/id/string()
>       let $publishedDate := $x/publicationDateTime/string()
>       let $putEarliest := if (not(map:contains($earliestPubDates, 
> $contentId))) then (
>                              let $dummy := map:put($earliestPubDates, 
> $contentId, $x/publicationDateTime)
>                              let $a := error("Adding earliest published date 
> " || $x/publicationDateTime)
>                              return $dummy
>                           ) else ()
>       let $putLatest := map:put($latestPubDates, $contentId, $publishedDate)
>       return ()
>
> return $buildMaps
> ----------------------------------
> Returns (in an error stack trace): "Adding earliest published date 
> 2014-09-03T14:46:07.757612Z"
>
>
> Is it something to do with when the order by is applied to the statement?
>
> Any help gratefully received
> Rachel
> _______________________________________________
> General mailing list
> General@developer.marklogic.com<mailto:General@developer.marklogic.com>
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com<mailto:General@developer.marklogic.com>
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to