Assigning incrementing number to 100ks of elements

Tuesday, 24 November 2015 · 2 messages
CB
Chuck Bearden24 Nov 2015 22:29 #

BaseX 8.3.1, installed on Linux today from zip archive.

I have about 137,000 target elements, each having an average of 550 descendant elements, and each taking about 45k of space on disk. The target elements each have an @uuid value, and I'd like to extract each @uuid value and assign it a unique number from an incrementing sequence of integers. I'd like to be able to start the sequence at an arbitrary value.

I tried a recursive function I borrowed and modified from a StackOverflow post:

declare function local:loop($seq, $count) {
  if(empty($seq)) then ()
  else
    let $prod  := $seq[1],
        $count := $count + 1
    return (
      <result>
        <id>{$count}</id>
        <uuid>{data($prod)}</uuid>
      </result>,
      local:loop(tail($seq), $count)
    )
};

and calling it like so:

return
<results>{
local:loop($pubs, 0)
}</results>

where $prod is a sequence of all the @uuid attributes (not the values, and not the whole elements).

My query fails with the error: [bxerr:BASX0005] Stack Overflow: Try tail recursion?

I'm using -Xmx6g and -Xss4m as flags for Java in the basexgui script.

Is there some way to get BaseX to use tail recursion? Or is there another approach to doing what I want?

Many thanks, Chuck

CG
Christian Grün24 Nov 2015 23:01 #

Hi Chuck,

Quoted text · Chuck Bearden · 3 lines
> target elements each have an @uuid value, and I'd like to extract each > @uuid value and assign it a unique number from an incrementing > sequence of integers.

There has recently been a thread on generating consecutive ids, it should answer some of your questions [1].

Quoted text · Chuck Bearden · 5 lines
> I tried a recursive function I borrowed and modified from a StackOverflow post: > [...] > I'm using -Xmx6g and -Xss4m as flags for Java in the basexgui script. > > Is there some way to get BaseX to use tail recursion?

Absolutely. You can rewrite function calls in recursive code to tail calls (but it’s hardly possible to do this automatically); see [2] for some examples.

Hope this helps, Christian

[1] https://www.mail-archive.com/basex-talk%40mailman.uni-konstanz.de/msg07120.html [2] https://en.wikipedia.org/wiki/Tail_call


⚡Generated with XQuery