Hi, Will:

The / operator sorts the expression results on the right hand side based on 
document order, which can randomize results other than nodes from the same 
document.

Instead of the / operator, consider either the XQuery 3.0 ! operator (which 
doesn't sort) or use a for to preserve the ordering.


Hoping that's useful,


Erik Hennum

________________________________________
From: [email protected] 
[[email protected]] on behalf of Will Thompson 
[[email protected]]
Sent: Friday, August 23, 2013 10:19 AM
To: MarkLogic Discussion
Subject: [MarkLogic Dev General] Function streaming bug or feature?

I have been making function calls at the end of xpath statements as a kind
of best practice to hedge against the possibility that part of the path
may resolve to empty (and prevent calling a function that doesn't handle
empty): a/b/x:y(.) - however, I recently came across a scenario where this
is affecting the order of the called function output:

declare function local:dostuff(
  $a as xs:string?,
  $b as xs:string?
) as element()*
{
  $a ! <a>{ $a }</a>,
  $b ! <b>{ $b }</b>
};

let $x := <x><a>a</a><b>b</b></x>
for $i in (1 to 100)
return
deep-equal(
  $x/local:dostuff(./a, ./b),
  local:dostuff($x/a, $x/b))

I expect these to always be equal since $x is a sequence of 1, so
dostuff() is only ever called once (with identical parameters). Or I would
expect both calls to return results in non-deterministic order, but only
the first call is ever out of order:

deep-equal(
  local:dostuff($x/a, $x/b),
  local:dostuff($x/a, $x/b)) => always true

deep-equal(
  $x/local:dostuff(./a, ./b),
  $x/local:dostuff(./a, ./b)) => non-deterministic



-Will

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to