Re: [basex-talk] Weird behaviour with sequence and random:integer
Everytime one learns something new. Thanks for the explanation! M. On 22/05/24 15:41, Christian Grün wrote: Hi Marco, > ("a", "b", "c")[trace(1 + random:integer(3))] The filter expression is defined in such a way that the predicate is evaluated anew for every item of the sequence. If you want random:integer(3) to be evaluated only once, you can either bind it to a variable… let $r := random:integer(3) + 1 return ("a", "b", "c")]$r] …or use functions like fn:subsequence: subsequence(("a", "b", "c"), random:integer(3) + 1, 1) Hope this helps, Christian Marco Lettere schrieb am Mi., 22. Mai 2024, 15:34: Dear all, I have this strange behavior when running in BaseX 10.4: ["a","b","c"](1 + random:integer(3)) I got something empty result, sometimes (correctly) one out of the three, sometimes two results... I report the results and the trace in [1] and [2]. What is the reason for this? Thank you. Marco. [1] Two results a c Evaluating: 1 3 3 Compiling: - rewrite list to xs:string sequence: ("a", "b", "c") - swap operands: (1 + random:integer(3)) Optimized Query: ("a", "b", "c")[trace((random:integer(3) + 1))] Query: ("a", "b", "c")[trace(1 + random:integer(3))] Result: - Hit(s): 2 Items - Updated: 0 Items - Printed: 3 b - Read Locking: (none) - Write Locking: (none) Timing: - Parsing: 0.21 ms - Compiling: 0.4 ms - Optimizing: 0.1 ms - Evaluating: 0.57 ms - Printing: 0.02 ms - Total Time: 1.31 ms [2] Empty result () Evaluating: 3 3 1 Compiling: - rewrite list to xs:string sequence: ("a", "b", "c") - swap operands: (1 + random:integer(3)) Optimized Query: ("a", "b", "c")[trace((random:integer(3) + 1))] Query: ("a", "b", "c")[trace(1 + random:integer(3))] Result: - Hit(s): 0 Items - Updated: 0 Items - Printed: 0 b - Read Locking: (none) - Write Locking: (none) Timing: - Parsing: 0.16 ms - Compiling: 0.41 ms - Optimizing: 0.15 ms - Evaluating: 0.56 ms - Printing: 0.02 ms - Total Time: 1.3 ms Query Plan: a b c 3 1
Re: [basex-talk] Weird behaviour with sequence and random:integer
Hi Marco, > ("a", "b", "c")[trace(1 + random:integer(3))] The filter expression is defined in such a way that the predicate is evaluated anew for every item of the sequence. If you want random:integer(3) to be evaluated only once, you can either bind it to a variable… let $r := random:integer(3) + 1 return ("a", "b", "c")]$r] …or use functions like fn:subsequence: subsequence(("a", "b", "c"), random:integer(3) + 1, 1) Hope this helps, Christian Marco Lettere schrieb am Mi., 22. Mai 2024, 15:34: > Dear all, > > I have this strange behavior when running in BaseX 10.4: > > ["a","b","c"](1 + random:integer(3)) > > I got something empty result, sometimes (correctly) one out of the > three, sometimes two results... > > I report the results and the trace in [1] and [2]. > > What is the reason for this? > > Thank you. > > Marco. > > [1] Two results > a > c > > Evaluating: > 1 > 3 > 3 > Compiling: > - rewrite list to xs:string sequence: ("a", "b", "c") > - swap operands: (1 + random:integer(3)) > Optimized Query: > ("a", "b", "c")[trace((random:integer(3) + 1))] > Query: > ("a", "b", "c")[trace(1 + random:integer(3))] > Result: > - Hit(s): 2 Items > - Updated: 0 Items > - Printed: 3 b > - Read Locking: (none) > - Write Locking: (none) > Timing: > - Parsing: 0.21 ms > - Compiling: 0.4 ms > - Optimizing: 0.1 ms > - Evaluating: 0.57 ms > - Printing: 0.02 ms > - Total Time: 1.31 ms > > > [2] Empty result > () > > Evaluating: > 3 > 3 > 1 > Compiling: > - rewrite list to xs:string sequence: ("a", "b", "c") > - swap operands: (1 + random:integer(3)) > Optimized Query: > ("a", "b", "c")[trace((random:integer(3) + 1))] > Query: > ("a", "b", "c")[trace(1 + random:integer(3))] > Result: > - Hit(s): 0 Items > - Updated: 0 Items > - Printed: 0 b > - Read Locking: (none) > - Write Locking: (none) > Timing: > - Parsing: 0.16 ms > - Compiling: 0.41 ms > - Optimizing: 0.15 ms > - Evaluating: 0.56 ms > - Printing: 0.02 ms > - Total Time: 1.3 ms > Query Plan: > > > >a >b >c > > > > >3 > > 1 > > > > > >
[basex-talk] Weird behaviour with sequence and random:integer
Dear all, I have this strange behavior when running in BaseX 10.4: ["a","b","c"](1 + random:integer(3)) I got something empty result, sometimes (correctly) one out of the three, sometimes two results... I report the results and the trace in [1] and [2]. What is the reason for this? Thank you. Marco. [1] Two results a c Evaluating: 1 3 3 Compiling: - rewrite list to xs:string sequence: ("a", "b", "c") - swap operands: (1 + random:integer(3)) Optimized Query: ("a", "b", "c")[trace((random:integer(3) + 1))] Query: ("a", "b", "c")[trace(1 + random:integer(3))] Result: - Hit(s): 2 Items - Updated: 0 Items - Printed: 3 b - Read Locking: (none) - Write Locking: (none) Timing: - Parsing: 0.21 ms - Compiling: 0.4 ms - Optimizing: 0.1 ms - Evaluating: 0.57 ms - Printing: 0.02 ms - Total Time: 1.31 ms [2] Empty result () Evaluating: 3 3 1 Compiling: - rewrite list to xs:string sequence: ("a", "b", "c") - swap operands: (1 + random:integer(3)) Optimized Query: ("a", "b", "c")[trace((random:integer(3) + 1))] Query: ("a", "b", "c")[trace(1 + random:integer(3))] Result: - Hit(s): 0 Items - Updated: 0 Items - Printed: 0 b - Read Locking: (none) - Write Locking: (none) Timing: - Parsing: 0.16 ms - Compiling: 0.41 ms - Optimizing: 0.15 ms - Evaluating: 0.56 ms - Printing: 0.02 ms - Total Time: 1.3 ms Query Plan: a b c 3 1