Why would the fn:last()
function not work while spawning?
This failed:
xquery version "1.0-ml";
let $items := (1, 2, 3)
return xdmp:spawn-function(function () {
$items[3 to fn:last()]
})
After some time I cancel the job because it does nothing.
Output: Cancelling fails with message indication function must be stopped manually.
This works just fine:
xquery version "1.0-ml";
let $items := (1, 2, 3)[3 to fn:last()]
return xdmp:spawn-function(function () {
$items
})
Output: Query completed successfully
The example for the docs of fn:last()
is showing a very similar usage of this function. The downside for using functions in predicates is though that they are evaluated for each item in the sequence. Using fn:subsequence
and optionally fn:count
should both be more efficient, and by-pass your issue:
let $items := (1, 2, 3)
return xdmp:spawn-function(function () {
xdmp:log(subsequence($items, 3, count($items))) (: you can omit 3rd param with same effect :)
})
HTH!