Closed GuntherRademacher closed 1 year ago
An excellent analysis! And a reasonable proposal to resolve the problem.
I noticed there are various other cases with minimum/maximum long values that cause questionable results or are rejected, e.g.:
(: [FOAR0002] Value out of range: 9223372036854775807. :)
<a/>[position() = 0 to 9223372036854775807]
…so I decided to change the general behavior of Range.value: If an over-/underflow occurs, I’m now passing on the maximum long value instead of raising an error.
Admittedly, the solution introduces new errors. For example, the following query had been rejected, whereas it now returns a wrong result (9223372036854775807
instead of 9223372036854775808
):
count(0 to 9223372036854775807)
There would be several ways to fix this (use BigInteger instances for large integers; use flags/constants to indicate infinite values; etc.), but I don’t think it’s worth fixing that. The specification of the language is pretty vague when it comes to handling edge cases, and there appears to be no XQuery implementation that yields 100% correct results for such cases.
Thanks a lot!
An XQuery positional filter for the last one or two elements of a sequence,
failed with this result, when there is just a single item in the context:
This is caused by Pos.get transforming the filter predicate to a range ending in Long.MAX_VALUE,
and Range.value producing a long overflow while calculating the range size,
where
mn == 0
andmx == Long.MAX_VALUE
.Actually the lower bound of the position range never needs to be less than 1, so the idea of this fix is to rewrite
to