Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created January 29, 2016 14:09
Show Gist options
  • Save ableasdale/d9ef310864d7fb554178 to your computer and use it in GitHub Desktop.
Save ableasdale/d9ef310864d7fb554178 to your computer and use it in GitHub Desktop.
MarkLogic: Aggregated Rebalancer Preview Fragment Counts
declare function local:update($map, $key, $num) {
let $key := fn:tokenize($key, "-")[3]
let $e := ( map:get($map, $key), 0) [1]
return map:put($map, $key, $e + $num)
};
let $map:= map:map()
let $_ :=
for $f in xdmp:document-get("/path/to/result.xml")/result/*:forest-counts
return (
local:update($map, $f/*:forest-name/fn:string(.), fn:sum ($f//*:active-fragment-count)),
local:update($map, $f/*:forest-name/fn:string(.), - fn:sum ($f//*:rebalance-fragment-count/*:fragment-count)),
for $d in $f//*:rebalance-fragment-count[*:fragment-count != 0]
return local:update($map, $d/*:rebalance-destination/fn:string(.), fn:sum ($d/*:fragment-count))
)
for $k in map:keys($map)
let $v := map:get($map, $k)
order by $v
return
($k ||":"|| $v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment