Skip to content

Instantly share code, notes, and snippets.

@tternquist
Last active May 31, 2017 17:03
Show Gist options
  • Save tternquist/3fcb8cc6c8bfc768f865366cf86f9444 to your computer and use it in GitHub Desktop.
Save tternquist/3fcb8cc6c8bfc768f865366cf86f9444 to your computer and use it in GitHub Desktop.
Batch processing in marklogic with spawn function
xquery version "1.0-ml";
let $input := for $i in (1 to 100) return $i
let $batch-size := 2
let $input-size := fn:count($input)
let $num-batches := xs:int(math:ceil($input-size div $batch-size ))
let $result :=
for $batch-start in (1 to $num-batches)
let $processing-seq := $input[($batch-size * ($batch-start - 1) + 1) to ($batch-size * ($batch-start ))]
return
xdmp:spawn-function(function() {
fn:string-join($processing-seq ! fn:string(.),",")
},
<options xmlns="xdmp:eval">
<result>true</result>
<transaction-mode>update-auto-commit</transaction-mode>
</options>)
return ($result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment