Skip to content

fix(core): check a PartiQL number's magnitude before its digit count - #1376

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/958-partiql-number-order
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/958-partiql-number-order

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

check_number in crates/core/src/partiql/number.rs now checks the magnitude range of a PartiQL number before its digit count. A number with more than 38 significant digits and a magnitude out of range gets the overflow or the underflow text, as DynamoDB gives. Before, it got Attempting to store more than 38 significant digits in a Number.

check_number is the one PartiQL number check. It reads the N values in Parameters and the number literals in a statement, so both get the new order. The conversion check still comes first. The classic number check of the item operations does not change.

The changes:

  • check_number moves the digit check after the magnitude checks. The module doc and the function doc say so.
  • the_magnitude_range_comes_before_the_digit_count and a_literal_names_the_magnitude_before_the_digit_count in number/tests.rs hold the measured rows.
  • tests/test_partiql_numbers.py has four more rows, two for a parameter and two for a literal.

Fixes #958

Why

DynamoDB was measured in us-east-1 on 23 November 2026, with ExecuteStatement on a table that does not exist. Each request went out twice and got the same answer both times. The number check answers before the table lookup: the number 1 gets ResourceNotFoundException.

F is the forty digits 1234567890123456789012345678901234567890, which have 39 significant digits.

Number DynamoDB ExtendDB before
F E200, as a parameter Number overflow. Attempting to store a number with magnitude larger than supported range Attempting to store more than 38 significant digits in a Number
F E-200, as a parameter Number underflow. Attempting to store a number with magnitude smaller than supported range the digit count text
F, as a parameter the digit count text the digit count text
F E200, F E-200 and F, as a literal the same three texts, with under root the digit count text, with under root

The same order holds in these cases, each measured twice:

  • 39 digits at each end of the magnitude range. With E87 and E-168 the number is in range and gets the digit count text. With E88 and E-169 it gets the overflow and the underflow text.
  • F with the exponent 2147483647, as a parameter: the underflow text, from the 32-bit wrap. F with the exponent 2147483600: the overflow text.
  • A number inside a map, a list or a set, as a parameter and as a literal. A literal names its place, for example under root.x or under root[0].
  • UPDATE, INSERT, SELECT and DELETE, BatchExecuteStatement and ExecuteTransaction.

The literal F with the exponent 2147483647 got InternalFailure (HTTP 500) from DynamoDB, twice. ExtendDB gives it the underflow text with under root, as it does for the same number as a parameter.

The item operations, such as PutItem, answered the digit count text for F E200 and F E-200 on 11 November 2026. So the classic number check in crates/core/src/validation/number.rs keeps its order.

Testing done

  • cargo test -p extenddb-core --lib --no-fail-fast: 1148 passed, 1 ignored, which main ignores too. cargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A control put back the order of main and kept the new tests. Both new tests failed. In the parameter table, 7 of 10 rows got the digit count text. In the literal table, 8 of 9 rows did. The rows that passed expect the digit count text in both orders. The other 18 tests of the module passed on both orders, so no earlier test held the old order.
  • Against a release build on SQLite, 34 of the 35 measured requests got the status, type and text of DynamoDB. The one that differs is the literal F with the exponent 2147483647, which DynamoDB answers with HTTP 500.
  • tests/test_partiql_numbers.py against that build: 109 passed and 1 xfailed, the four new rows among the passes. The xfail is the mark for a server built without the MongoDB crate.
  • The last amend changed a docstring and a comment of the Python test file. The runs above used the commit before it.

Production is +12 -8, of which the code is +3 -3. The tests are +74 -5.

git merge-tree shows no conflict with main or with #781, the one open PR that changes a file of this PR.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

A PartiQL number with more than 38 significant digits and a magnitude
out of range got the digit count text. DynamoDB answers the magnitude
fault for such a number.

DynamoDB was measured in us-east-1 on 23 Nov 2026, with ExecuteStatement
on a table that does not exist. Each request went out twice and got the
same answer both times. The number check answers before the table
lookup. F is the forty digits 1234567890123456789012345678901234567890:

- A parameter of F E200 gets "Number overflow. Attempting to store a
  number with magnitude larger than supported range".
- A parameter of F E-200 gets "Number underflow. Attempting to store a
  number with magnitude smaller than supported range".
- A parameter of F gets "Attempting to store more than 38 significant
  digits in a Number".
- A literal gets the same texts with " under root" after them.

The order is the same for 39 digits at each end of the magnitude
range. It is also the same for a number in a map, a list or a set, and
for INSERT, SELECT and DELETE. BatchExecuteStatement and
ExecuteTransaction keep it too.

check_number now checks the magnitude range before the digit count.
The item operations, such as PutItem, answered the digit count for
these numbers on 11 Nov 2026. The classic number check therefore keeps
its order.

Fixes #958.

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed at 97651d0.

Docs — outside the diff

  1. docs/manuals/07-upgrade-manual.md:385 — Please add an entry under Behavior Changes by Release for the new message order. v1.1.0 (and v1.0.0, v0.1.15) carry the old order in check_number, and on this head 1234567890123456789012345678901234567890E200 as a parameter or literal now gets Number overflow... where those releases answered Attempting to store more than 38 significant digits in a Number. The manual already records the same kind of message-only number change for #619 at line 1227, so a matching bullet would close this.

@navareamol navareamol self-assigned this Dec 3, 2026

@navareamol navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the new order on a server built from this head against main with 23 numbers on 20 request forms, parameters and literals, ExecuteStatement and ExecuteTransaction. Every form that gave the digit count text for F E200, F E-200 and a 39 digit number with E88 or E-169 on main gives the overflow or underflow text here, and the forms that should not change did not. The four new rows in test_partiql_numbers.py fail on main and pass here.

I think one edge is not covered. The magnitude uses all digits including trailing zeros, and the digit count does not. F (the forty digits, one trailing zero) with E86 is in range and with E87 is an overflow by that rule, and the measured boundary rows use 39 digit numbers without a trailing zero. Could you measure F E86 and F E87 on the live service, and add them to the Rust table if they match?

The wire test file has rows for E200 and E-200 only. Could one row for the boundary (39 digits with E88) be added there too, so the boundary is held on the wire?

I will approve once the trailing zero boundary is measured or the description says it was not.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PartiQL: check_number reports the digit count before the magnitude, and DynamoDB reports the magnitude first

3 participants