Skip to content

fix(expression): operator cap, syntax error wording, PutItem map keys - #558

Open
LeeroyHannigan wants to merge 39 commits into
mainfrom
fix/expression-operator-limits
Open

LeeroyHannigan wants to merge 39 commits into
mainfrom
fix/expression-operator-limits

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

The branch merges main at 8c643330c (d44387b) and adds six commits:

  • 130677b moves TestPlaceholderKeyLength into tests/test_expression_placeholder_key_length.py.
  • 1c43200 checks each Scan range field on its own. TotalSegments: 0 without a Segment now answers the TotalSegments range. Before this commit it answered the operator count or the missing Segment. Segment: -1 without a TotalSegments answers the Segment range. The range rows assert their full texts, and the row s41 covers the new case.
  • cd31920 replaces the text match is_syntax_error with a typed fault from the condition parser, ConditionFault::Syntax or ConditionFault::Other. No answer changes.
  • 75505b7 adds the rows a60 and b05 and rewrites a test comment claiming that ExtendDB has no one-condition-per-key check.
  • 3b42c2d adds the v1.1.0 entry to docs/manuals/07-upgrade-manual.md.
  • ab59fc2 drops four re-exports no caller uses and lists # max_expression_operators = 300 in the config template that extenddb init writes.

After the review of 24 Nov, two more commits:

  • ae298f4 moves the test module of crates/core/src/expression/parser.rs unchanged into parser_tests.rs. parser.rs goes from 702 lines to 398.
  • ee1d541 tells the reader of the upgrade manual to remove max_expression_operators before a rollback to 1.0.0. A 1.0.0 binary refuses to start with a configuration that holds the key.

What

Three expression checks now answer as DynamoDB does.

Operator cap

A condition, filter or key condition expression with more than 300 operators is refused with Invalid <Kind>: The expression contains too many operators; operator count: <n>, where <n> is the full count. 300 is accepted. The cap is the [limits] setting max_expression_operators, default 300. On PutItem, UpdateItem and DeleteItem the text matches the service after the 1 validation error detected: prefix, which #399 adds.

The count follows the service: every comparison operator, AND, OR, NOT, BETWEEN, IN and every function call (size included) counts one. Parentheses, paths, placeholders and the elements of an IN list count zero. BETWEEN :a AND :b counts one, and its inner AND is not counted. Examples from the measurements: attribute_not_exists(pk) followed by 300 OR #v = :v terms answers 601, 160 #v BETWEEN :v AND :v terms joined by OR answer 319, and 230 size(#v) = :v terms answer 689.

It applies to ConditionExpression on PutItem, UpdateItem and DeleteItem, to FilterExpression on Scan and Query, and to KeyConditionExpression on Query. The legacy ScanFilter, QueryFilter and Expected parameters are not counted: the service accepts 160 conditions in each. An UpdateExpression has no operator cap: a chain of arithmetic is a syntax error first, and 301 SET assignments are accepted. TransactWriteItems is unchanged. The service counts it the same way as PutItem. A Put of 151, 200 or 300 #v = :v terms joined by OR answers 301, 399 or 599. A ConditionCheck of 151 terms answers 301, and the service evaluates a Put of 150 terms. This PR does not apply the cap there.

On the write paths and on Scan, the count runs after the parse and after one pass over the placeholders and operand types. It runs before the unused name and value check and the table lookup. The pass reports the first fault in the order of the expression. It refuses an undefined name or value and a begins_with prefix that is not S or B. It also refuses a literal that does not order in an ordering comparison or BETWEEN. The older checks validate_ordering_operand_types and validate_begins_with_operands stay for the legacy ScanFilter and QueryFilter, for TransactWriteItems and for PartiQL joins. The pass also refuses undefined placeholders, so it would change what those callers answer. For TransactWriteItems that change is #1045. On UpdateItem the server checks the condition before the update expression. On Query a syntax error in the key condition comes first, then the key condition count, then the key grammar. A key condition over the cap goes through the same pass before the count, so its undefined placeholder or operand type fault answers first. The filter gets the same pass and count as on Scan, after the key condition. On Scan the Limit, Segment and TotalSegments ranges come before the filter, each field checked when it is present. PartiQL lifts the cap for the requests it writes for a statement, and its parser counts the statement.

Syntax error wording

A repeated or misplaced operator or keyword answers Invalid <Kind>: Syntax error; token: "<t>", near: "<window>" on condition, filter, key condition, update and projection expressions. The exceptions are NOT and OR in a key condition, which the service answers with Invalid operator used in KeyConditionExpression, and so does this PR. The window starts at the token before the offending one and ends at the token after it, keeping the whitespace of the source. #v = = :v answers token: "=", near: "= = :v", #v==:v answers near: "==:v", and = #v = :v answers near: "= #v". When the expression ends where a token is required, the token is <EOF> and the window is the last token: #v = :v AND answers token: "<EOF>", near: "AND". When the faulty token is the first one, the window starts at the start of the expression and keeps the leading whitespace: = #v = :v answers near: " = #v".

The update parser built its window by searching the source for the token's text. The window was wrong when the same text appeared earlier in the expression. It now uses the token positions.

The token is shown as the client wrote it, so #v = :v and and #v = :v answers token: "and", near: "and and #v".

Other syntax error texts are unchanged. The condition parser reports a syntax error as the Syntax variant of ConditionFault. The key condition path keeps that variant and leaves every other refusal to the key condition parser.

Too-long keys in the expression maps on PutItem

The shared deserializer already refused a key over 255 bytes in ExpressionAttributeNames or ExpressionAttributeValues. PutItem classified deserializer errors with its own list and answered SerializationException. PutItem now uses the shared classifier and answers the ValidationException: ExpressionAttributeNames contains invalid key: The expression attribute map contains a key that is too long; size of key: 256. The bound is 255 bytes of UTF-8, and it is checked before any expression check.

The ExpressionAttributeValues text now carries the ; size of key: <n> suffix too. The service answered it on PutItem, Scan and Query in these measurements, and the existing test that asserted its absence is updated.

The shared classifier also changes the answer to an empty attribute name in ExpressionAttributeNames on PutItem. {"#v": ""} answers ValidationException ExpressionAttributeNames contains invalid value: Empty attribute name for key #v. Main answers SerializationException with the same text after Start of structure or map found where not expected: . The service answers ValidationException with the write prefix.

Docs

docs/dynamodb-limits.md lists the cap with the expression limits. docs/manuals/07-upgrade-manual.md gets a v1.1.0 entry under "Behavior Changes by Release". It covers the cap, the syntax error texts, the PutItem map key answers and the Scan range order. It names max_expression_operators as the way to raise the cap.

Why

Fixes #501, which records three expression shapes that DynamoDB refuses or words differently.

Every expected response in the tests was measured on 2026-10-25, 2026-11-19, 2026-11-20 or 2026-11-23 in us-east-1, each case sent twice with the same answer.

Related behaviour

Files

key_condition.rs grew to 2,029 lines and projection.rs to 754. The last commit before the rustfmt commit is a pure move of the key condition resolution and the two test modules into their own files. It uses the #[path] pattern evaluator_tests.rs uses. crates/engine/src/query.rs is 800 lines on main and 754 here. crates/core/src/expression/parser.rs is 398 lines (543 on main), crates/engine/src/partiql/mod.rs is 689 (680 on main), and the test files tests/test_expression_operator_limits.py and tests/test_expression_placeholder_key_length.py are 605 and 151.

Overlaps

Three open PRs add their own copies of checks this PR adds, and each conflicts with this branch:

Whichever PR merges second drops its copy: validate_placeholders_and_operands here against the reference checks of #399 and #479, and validate_scan_ranges here against validate_scan_request_body of #850.

Rebase on #429

Rebased on main at f49c5f82 (#429), which includes #511. Both changed crates/core/src/expression/key_condition.rs, and #511 also changed the pub use block of crates/core/src/expression/mod.rs, so the first commit conflicted in those two files and the move commit was redone.

#511 moved the clause loop of parse_key_condition into parse_clauses, which parse_key_condition and its new key_condition_clause_operands both call. parse_clauses now takes the expression text and builds the syntax error window, so both callers report a repeated or misplaced operator or keyword in the Syntax error; token: form. parse_key_condition_from passes the request's text. parse_key_condition and key_condition_clause_operands pass none, so their window joins the token texts. A unit test checks that key_condition_clause_operands refuses the same expressions as parse_key_condition, with the same error. Authorization calls key_condition_clause_operands to find dynamodb:LeadingKeys and reads the clauses it returns. Of an error it reads only that one occurred, never the text. A key condition that does not parse binds no key there, as on main, and the client sees the engine's error with the source window. In mod.rs the merge keeps both sets of exports, and in the test module it keeps both sides' new tests.

#429's checks run on the parsed key condition, after the parser, and keep their own texts. They are one condition per key, the condition count, HASH coverage, the RANGE gap and the value type.

The move commit moves the same items from the rebased file. #429 added resolve_multipart_with, resolve_key_schema_with, resolve_key_schema and for_each_clause to the impl KeyCondition block, and #429 and #511 added 20 tests to the test module. The whole block and resolve_path_attr go to key_condition_resolve.rs, and the whole test module goes to key_condition_tests.rs. SortKeyCondition::path, which #429 added, stays next to SortKeyCondition in key_condition.rs. key_condition.rs was 2,029 lines before the move and is 645 at this head. key_condition_resolve.rs is 458 lines. The test module, 997 lines after the move, is now three files: key_condition_tests.rs (372 lines), key_condition_classify_tests.rs (425) and key_condition_resolve_tests.rs (223).

crates/engine/src/query.rs merged without a conflict. handle_query calls parse_key_condition_expr, which runs the key condition count, before resolve_key_schema_with. The count is still reported ahead of the condition count, the missing HASH attribute, the RANGE gap and the value type check. The FilterExpression count is where it was: after the undefined name check, before the unused placeholder check, and after #429's key condition checks. The service reports the filter count ahead of #429's type check (see Related behaviour).

Merging with #484

A trial merge with #484's head 374628096 conflicts in crates/core/src/expression/key_condition.rs, crates/core/src/expression/mod.rs, crates/engine/src/expression_helpers.rs and crates/engine/src/query.rs.

Whichever of #558 and #484 merges second resolves these files. #484 can then call validate_placeholders_and_operands in place of its own reference and begins_with checks.

Testing done

Tests

  • tests/test_expression_operator_limits.py: 63 tests covering the cap, its position and the checks ahead of it on PutItem, UpdateItem, DeleteItem, Scan and Query. On the write paths the assertions compare the text after the service's 1 validation error detected: prefix, which ExtendDB does not emit (see Related behaviour). The Scan range rows assert the service's full text on DynamoDB and ExtendDB's full text on ExtendDB, until Scan range constraints: the service aggregates Limit, Segment and TotalSegments faults and uses two text forms by the value's size #563 brings the texts together. The row b05 is marked as an expected failure on ExtendDB (see Related behaviour).
  • tests/test_expression_placeholder_key_length.py: 5 tests of the key length on PutItem, Scan, Query and UpdateItem.
  • tests/test_expression_syntax_wording.py: 41 tests of the Syntax error; token: wording. tests/expression_fault_helpers.py holds the request helpers and the table fixture that the three files share.
  • tests/test_legacy_filter_operator_count.py: a 160-condition ScanFilter and QueryFilter are answered normally and a 160-condition Expected is evaluated. These pass on main, and they fail if the cap is applied to the legacy parameters.
  • tests/test_expression_attribute_map_validation.py: the updated test_value_key_too_long.
  • Unit tests at each check in crates/core/src/expression and crates/engine/src/expression_helpers.rs. Five mutations each fail a unit test. They are a cap of 301, no count on the condition path, and a key condition parsed without its source text. The other two are main's clause parser inside key_condition_clause_operands, and a Syntax fault treated as any other refusal.

Gates

The gates ran on the tree of ab59fc261:

  • cargo +1.97.0 fmt --all -- --check: clean.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine -p extenddb-app --all-targets -- -D warnings: clean, also with --features extenddb-engine/backup-test-hooks.
  • cargo +1.91.1 check -p extenddb-core -p extenddb-engine -p extenddb-app --all-targets: clean.
  • --lib tests: core 1180 passed and 1 ignored, engine 879 passed.

Wire, on a dev-mode SQLite server built from ab59fc261: the five test files above, 123 passed and 1 expected failure. At b4260658d the four files then present passed on PostgreSQL (122), and tests/test_expression_operator_limits.py passed against DynamoDB (66 in each of three runs on 2026-11-20). CI runs the rest, MongoDB and Cassandra included.

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. There is no wire, Storage trait, auth model or on-disk change.

Breaking changes

An expression of more than 300 operators, which 1.0.0 evaluated, gets ValidationException after the upgrade, and nothing is read or written. A deployment that needs the old behaviour sets max_expression_operators under [limits] above its largest expression. A client that matches error texts sees the Syntax error; token: texts. On PutItem it also sees ValidationException in place of SerializationException for a too-long or empty expression map key. docs/manuals/07-upgrade-manual.md has the v1.1.0 entry.


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.

…ice does, and classify too-long map keys on PutItem

Condition, filter and key condition expressions now count operators the way
Amazon DynamoDB does: every comparison, AND, OR, NOT, BETWEEN, IN and
function call (size included) counts one; parentheses, paths, placeholders
and list elements count zero. A count above 300 is refused with
"Invalid <Kind>: The expression contains too many operators; operator
count: <n>". On the write paths the count runs after the ordering operand
type check and before the unused name and value check and the table lookup;
on Query it runs ahead of the key grammar. TransactWriteItems is unchanged.

A repeated or misplaced operator or keyword now answers
"Syntax error; token: \"<t>\", near: \"<window>\"" on condition, filter, key
condition, update and projection expressions. The window runs from the token
before the offending one to the token after it, with the source whitespace
kept; at the end of input the token is <EOF> and the window is the last
token. Other syntax error texts are unchanged.

PutItem classified deserializer errors itself and answered a too-long key in
ExpressionAttributeNames or ExpressionAttributeValues as SerializationException.
It now uses the shared classifier, which answers the ValidationException. The
ExpressionAttributeValues text carries the "; size of key: <n>" suffix, as
the service answers on PutItem, Scan and Query.

Measured on 2026-10-25 between 10:39 and 10:52 UTC, each case twice.

Fixes #501
… and the syntax error wording

tests/test_expression_operator_limits.py covers every row the change encodes,
from measurements on 2026-10-25 between 10:39 and 10:52 UTC. On the write
paths the assertions compare the text after the service's
"1 validation error detected: " prefix, which ExtendDB does not emit.
test_value_key_too_long now expects the size suffix.
…tion and projection tests into their own files

Pure move. key_condition.rs had grown to 2029 lines and projection.rs to 754;
the resolve methods go to key_condition_resolve.rs and the two test modules
to key_condition_tests.rs and projection_tests.rs, using the #[path] pattern
evaluator_tests.rs already uses.
…ve legacy filters out of the operator count

A syntax error at a lower-case keyword names the token as the client wrote
it: "#v = :v and and #v = :v" answers token "and", not "AND", on
FilterExpression, ConditionExpression and KeyConditionExpression (measured
2026-10-25). The token is now taken from the source text, as the window
already was.

Scan and Query counted the expression they build from a legacy ScanFilter or
QueryFilter, so 151 or more legacy conditions were refused as too many
operators. The service accepts 160 conditions in ScanFilter, QueryFilter and
Expected (measured 2026-10-25). The count now applies to a FilterExpression
only; Expected was not counted before this change.
… case as failing on MongoDB

On MongoDB, a 300-operator UpdateItem condition answers InternalServerError:
the MongoDB filter compiler nests one level per OR or AND, and a chain of 150
terms fails inside MongoDB. The compiler is not changed here. The refusal
above the cap stays an unconditional test; the evaluation at the cap is now a
test of its own with a strict expected failure on MongoDB.
…the first token

When the faulty token is the first one, the service starts the near window
at the start of the expression: `  = #v = :v` answers `near: "  = #v"` on
FilterExpression, KeyConditionExpression and ProjectionExpression (measured
2026-10-25 at 16:54 UTC, each request twice). The window started at the
token. A unit test and a wire test pin the measured rows.
@LeeroyHannigan
LeeroyHannigan force-pushed the fix/expression-operator-limits branch from 98fb237 to 077d435 Compare November 1, 2026 09:47
@navareamol navareamol added the v1 Needed for the 1.0 release label Nov 3, 2026
@navareamol navareamol added this to the 1.0 milestone Nov 3, 2026
@demohan demohan self-assigned this Nov 12, 2026

@demohan demohan 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.

Two regressions block this. (1) The operator count runs ahead of the undefined placeholder and operand type checks, which changes answers main gave correctly on Scan and Query. (2) After a rebase on main, PartiQL statements with NOT are refused, because the count runs on the generated text. The inline comments list the remaining items with the service's answers. TransactWriteItems has no cap on main either, so I will file it separately, unless you prefer to include it here.

Comment thread crates/engine/src/scan.rs Outdated
if filter_maps.is_none()
&& let Some(ref f) = filter
{
crate::expression_helpers::check_operator_count(f, ExpressionKind::Filter)?;

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.

The count runs before the operand type and undefined placeholder checks. On the service, a Scan filter of 150 #v = :v terms joined by OR plus OR #v < :b, with :b a BOOL, answers Invalid FilterExpression: Incorrect operand type for operator or function; operator or function: <, operand type: BOOL, and main answers the same. This branch answers operator count: 301. With 151 terms plus OR #v = :zz and :zz undefined, the service and main answer An expression attribute value used in expression is not defined; attribute value: :zz, and this branch answers operator count: 303. begins_with(#v, :n) with :n an N value behaves the same way. The static undefined placeholder check needs to run ahead of the count here, because main finds an undefined placeholder only during evaluation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6865836. Before the count, a Scan filter now goes through one left-to-right pass over its placeholders and operands. The pass refuses an undefined name or value and a begins_with prefix that is not S or B. It also refuses a literal that does not order in an ordering comparison or BETWEEN. 61e4288 runs the pass on a key condition over the cap too. #x = :p and 150 #v = :v terms joined by AND now answer the undefined #x, as main and the service do. TestChecksAheadOfTheCount in tests/test_expression_operator_limits.py covers the three shapes here on Scan and Query, and five key condition rows.

Comment thread crates/engine/src/query.rs Outdated
// FilterExpression only: a legacy QueryFilter of 160 conditions is
// accepted (measured 2026-10-25).
if filter_maps.is_none() {
crate::expression_helpers::check_operator_count(filter_expr, ExpressionKind::Filter)?;

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.

Same order as in scan.rs. A Query filter of 150 terms plus OR #v < :b answers the operand type error on the service and on main, and operator count: 301 here. The undefined name case already matches: 151 terms plus OR #x = :v answers the undefined name text on the service and here. A test for that order, and one with an unused :u (the service answers the count), would pin the position. Neither exists yet.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6865836: the Query filter goes through the same pass as Scan, ahead of the count. 61e4288 runs it on a key condition over the cap as well, so an undefined placeholder or a wrong operand type there answers first. TestChecksAheadOfTheCount::test_query_filter covers the operand type, undefined value, undefined name and begins_with rows. test_key_condition covers five key condition rows. For the unused :u beside 151 terms, the service answers operator count: 301, and so does this branch, in test_query_count_beats_an_unused_value.

Comment thread crates/engine/src/expression_helpers.rs Outdated
.map_err(|e| prefix_expression_error(e, ExpressionKind::Condition))?;
// After the operand type check (an ordering operator on a BOOL beats
// the count), before the unused placeholder check and the table lookup.
check_operator_count(expr, ExpressionKind::Condition)?;

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.

On PutItem, a condition of 151 terms plus OR #v = :zz with :zz undefined answers Invalid ConditionExpression: An expression attribute value used in expression is not defined; attribute value: :zz on the service. This branch answers operator count: 303. The doc comment at line 101 gives the service's order, and the code counts before the undefined value check.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6865836. resolve_condition runs the same pass before the count, so 151 terms plus OR #v = :zz answers the undefined value on PutItem, UpdateItem and DeleteItem. On these three operations the service puts 1 validation error detected: before that text, and the test compares the text after the prefix. 61e4288 runs the pass in parse_key_condition_expr when a key condition is over the cap, so the same order holds for a Query key condition.

Comment thread crates/engine/src/expression_helpers.rs Outdated
///
/// Measured 2026-10-25 (us-east-1): the check runs after the syntax, reserved
/// word, undefined placeholder and operand type checks and before the unused
/// placeholder check and the table lookup. `TransactWriteItems` counts a

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.

On the service, TransactWriteItems counts as PutItem does. A Put or ConditionCheck with 151 #v = :v terms joined by OR answers operator count: 301, 200 terms answer 399, 300 terms answer 599, and 150 terms are evaluated. PutItem with 200 and 300 terms answers 399 and 599. Please correct this sentence and the PR description.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Corrected in 75b03df. The doc comment now says that TransactWriteItems counts the same way as PutItem and that this check does not run there. It gives the service's answers. A Put of 151, 200 and 300 terms answers 301, 399 and 599. A ConditionCheck of 151 terms answers 301, and the service evaluates a Put of 150 terms. I've corrected the two sentences in the description too.

Comment thread crates/engine/src/scan.rs Outdated
if filter_maps.is_none()
&& let Some(ref f) = filter
{
crate::expression_helpers::check_operator_count(f, ExpressionKind::Filter)?;

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.

On main, PartiQL calls handle_scan, handle_query, handle_update_item_with and handle_delete_item with text from expr_bridge::condition_text. That function pushes NOT onto each predicate, so the text has more operators than the statement. Merged with main, SELECT * FROM "t" WHERE NOT (v = 'y' AND ...) with 150 terms answers operator count: 449. The service and main return the item. The Query, UPDATE and DELETE forms with 101 terms answer 302, 304 and 304, and the service and main run them. The PartiQL parser already applies the limit to the statement.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 469404e. The cap is now the [limits] setting max_expression_operators, with a default of 300. PartiQL lifts it for the requests it writes for a statement, as it already raises the size and token limits there. Its parser still counts the statement. The SELECT with NOT over 150 terms returns the item, and the Query, UPDATE and DELETE forms with 101 terms run. TestPartiqlStatementCount covers all four.

@@ -175,10 +210,10 @@ fn parse_primary(
if tokens[*pos] == Token::In {

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.

#v IN IN (:v) answers Syntax error; token: "IN", near: "IN IN (" on the service, and expected '(' here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 695af26. Any token but ( after IN, and the end of input there, now answer the syntax error, so #v IN IN (:v) answers token: "IN", near: "IN IN (" on PutItem and on Scan.

clauses.push(parse_key_clause(tokens, &mut pos)?);
clauses.push(parse_key_clause(tokens, &src, &mut pos)?);

while pos < tokens.len() {

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.

NOT pk = :p and pk = :p AND NOT sk = :s answer Invalid KeyConditionExpression: Invalid operator used in KeyConditionExpression on the service. This branch answers Syntax error; token: "NOT", near: "NOT pk" and near: "AND NOT sk". pk = :p AND NOT answers Syntax error; token: "<EOF>", near: "NOT" on the service. pk = :p OR answers token: "<EOF>", near: "OR", and pk = :p = answers token: "=", near: ":p =". This branch answers only AND is supported between key conditions to both.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 1e2171c. A syntax error from the condition grammar now comes first, then the count, then the key condition rules. In those rules, OR between clauses and NOT at the start of a clause answer Invalid operator used in KeyConditionExpression. The five shapes here now get the service's answers.

# MongoDB with InternalServerError. This change does not touch that compiler.
# The MongoDB test runner sets EXTENDDB_TEST_MONGODB_CONTAINER.
# TODO: remove this marker once the MongoDB filter compiler flattens chains.
XFAIL_ON_MONGODB_DEEP_OR = pytest.mark.xfail(

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.

The marker depends on EXTENDDB_TEST_MONGODB_CONTAINER. In a MongoDB run without it, test_update_item_condition_at_the_cap_is_evaluated fails with assert 'InternalServerError' == 'ConditionalCheckFailedException'.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in eecaf95. The marker now reads the backend the way the other tests do, from EXTENDDB_TEST_BACKEND or else the server's config file. A MongoDB run without EXTENDDB_TEST_MONGODB_CONTAINER now reports the test as an expected failure. #571 removes the marker.

}

#[test]
fn measured_update_syntax_errors() {

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.

No test tells the token-position window apart from the old text search. SET #v = :a + :b, #w = :c + :d + :e answers Syntax error; token: "+", near: ":d + :e" on the service and on this branch, and main answers near: "+ :b, #w". That shape would pin the fix.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added a unit test in df22608 and a wire test in 3ab4e82, both with SET #v = :a + :b, #w = :c + :d + :e, which answers token: "+", near: ":d + :e". A window found by a search for the token's text answers near: "+ :b, #w", and both tests fail on it.

@@ -0,0 +1,997 @@
// Copyright 2026 ExtendDB contributors

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.

This file is 997 lines. Splitting it into parse, classify and resolve modules as pure moves would keep each under 600.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Split in 096330a as a pure move. key_condition_tests.rs keeps the parse tests (372 lines). The classification tests moved to key_condition_classify_tests.rs (425) and the resolution tests to key_condition_resolve_tests.rs (223). The crate runs the same 1,179 tests.

…n file

This is a pure move. tests/test_expression_operator_limits.py had 694 lines, and the placeholder key length rows are not about the operator count. TestPlaceholderKeyLength, five tests, moves to tests/test_expression_placeholder_key_length.py with the imports it uses from expression_fault_helpers. Its tests and their bodies are unchanged. The docstring of the operator limits file names the new file, and the two files have 563 and 151 lines.
…, and assert the range texts in full

`validate_scan_ranges` checked the Segment and TotalSegments ranges only when both fields were present. A Scan with `TotalSegments: 0` and no Segment went on to the filter checks, and answered the operator count of a 151-term filter, or the missing Segment. The service answers the TotalSegments range (measured 2026-11-23 in us-east-1, twice): `1 validation error detected: Value at 'TotalSegments' failed to satisfy constraint: Member must have value greater than or equal to 1`. The comment above the call said so. Each field is now checked when it is present, in the order the service lists several faults of one request: Limit, Segment, TotalSegments. `Segment: -1` without TotalSegments answers the Segment range the same way. The texts are unchanged.

TestScanRangesAheadOfTheCount gains the row s41 (151 terms, `TotalSegments: 0`), which fails on the previous production lines. Its rows now assert the full text by equality: the service's `Value at 'Limit'` and `Value at 'TotalSegments'` forms on DynamoDB, and ExtendDB's own texts on ExtendDB.
`parse_key_condition_expr` read a key condition with the condition grammar first and kept the grammar's refusal when `is_syntax_error` found `: Syntax error; token: "` in its message. The classification is now a type. The condition parser's functions return `ConditionFault`. Its `Syntax` variant is the service-worded error of a repeated or misplaced operator, keyword or path, and its `Other` variant is every other refusal. `parse_condition_classified` returns it, `parse_condition_from` flattens it to the error as before, and `parse_key_condition_expr` matches the variant. `is_syntax_error` is deleted. No answer changes: the engine's key condition order tests and the wire files pass unchanged, and a unit test checks the variant of nine refusals.
…comment on ExtendDB's check

The comment on test_key_condition_count_precedes_the_key_grammar said ExtendDB has no one-condition-per-key check. The check exists since the rebase on #429, for the key attributes. The rows the comment cited are now tests, measured 2026-11-23 in us-east-1, twice each, with the same answers:

- a60: `pk = :v AND` 150 `#v = :v` joined by AND answers `Invalid KeyConditionExpression: The expression contains too many operators; operator count: 301`, on the service and on ExtendDB. The count comes ahead of the one-condition-per-key check on both.
- b05: the same shape with 10 terms answers `Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key` on the service, before the table lookup. ExtendDB serves it with no items. It accepts a key condition clause on an attribute outside the key schema, and its check covers the key attributes only. The row is marked as an expected failure on ExtendDB, strict, so it fails when the clause is refused.

The module docstring adds the measurement date.
…ged expression answers

The upgrade manual lists the behaviour changes an existing deployment can see, and this change had none. The new entry at the top of "Behavior Changes by Release" states four changes:

- An expression over 300 operators is refused with the service's text and count, where 1.0.0 evaluated it. `max_expression_operators` under `[limits]` raises the cap.
- A repeated or misplaced operator or keyword answers the `Syntax error; token:` text in place of 1.0.0's own texts. The update expression window is built from the token positions.
- A too-long or empty expression map key on PutItem answers ValidationException in place of SerializationException, and the ExpressionAttributeValues text carries the `; size of key: <n>` suffix.
- The Scan Limit, Segment and TotalSegments ranges are checked before the expressions and the table lookup, each field on its own.

The entry names who is affected and says that no catalog migration is required.
…operator cap in the config template

`crates/core/src/expression/mod.rs` re-exported `count_operators`, `is_operator_or_keyword`, `syntax_error` and `token_text`. No code outside the module imports them: the parsers import `syntax_error` and `is_operator_or_keyword` from the module itself, and `count_operators` is called only inside `operator_count.rs`. The four names leave the `pub use` lines. `validate_operator_count` and `MAX_EXPRESSION_OPERATORS` stay.

The `[limits]` section of the config file that `extenddb init` writes listed `max_expression_tokens` and `max_expression_depth` as comments and left out the new setting. It now lists `# max_expression_operators = 300` after them.
LeeroyHannigan added a commit that referenced this pull request Nov 23, 2026
…n-depth

The base branch moved from b9148ec to ab59fc2. The merge includes
main at 8c64333 and the commits #558 added after b9148ec. Those
commits report a condition syntax error as a typed fault and check a
Segment or TotalSegments range without its partner. They also move the
placeholder key length tests into their own file and add the
one-condition-per-key rows. Two more add the v1.1.0 upgrade manual
entry and drop four re-exports of extenddb_core::expression that this
branch does not use.

tests/test_expression_operator_limits.py had the one conflict. This
branch removed XFAIL_ON_MONGODB_DEEP_OR from the file, with its use on
test_update_item_condition_at_the_cap_is_evaluated and the conftest
import that only the marker used. The base branch added a second marker,
XFAIL_ON_EXTENDDB_NON_KEY_CONDITION, and a range text check that calls
_is_real_dynamodb. The resolution keeps the new marker and drops the
MongoDB one. It imports _is_real_dynamodb again, without
configured_backend, which only the MongoDB marker used.

The base commits change none of the other files of this branch:
crates/storage-mongodb/src/pushdown.rs, pushdown_tests.rs,
docs/design/13-storage-mongodb.md and
tests/test_condition_nesting_depth.py merged as they were.

@demohan demohan 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.

The two regressions and the inline items from the earlier review are resolved at ab59fc2, except the Query lookup order, which #1208 now carries. 236 request shapes were sent twice each to the service and to a SQLite build of this head. No shape that matched the service at 077d435 or on main answers differently here.

  • Scan: 150 terms with OR #v < :b answer the BOOL operand error. 151 terms with :zz answer the undefined value error. begins_with with an N value answers the operand type error. Each matches the service, and each comes ahead of the count. Limit: 0 and TotalSegments: 0 also come ahead of the count.
  • PutItem, UpdateItem and DeleteItem: 151 terms with :zz answer the undefined value error.
  • PartiQL: a SELECT, UPDATE or DELETE with NOT over 101 to 150 terms runs, and a follow-up GetItem confirms the write. 151 and 200 terms answer operator count: 301. The cap is lifted per request: across 400 concurrent requests, the NOT statement returned its item 200 of 200 times, and the 151-term Scan was refused 200 of 200 times.
  • The syntax error windows, ADD and DELETE, projection, IN IN and key condition NOT and OR shapes match the service.
  • A Scan over the cap is refused without reading the table. The new checks add no measurable cost.
  • Each new test fails with its change reverted. CI is green on 64 of 64 checks.

I will approve once the two items below are done.

crates/core/src/expression/parser.rs

This file grew from 585 to 702 lines in 695af26 and cd31920. The inline mod tests starts at line 396, and moving it unchanged to parser_tests.rs brings the file under 600.

Comment thread docs/manuals/07-upgrade-manual.md Outdated
- PutItem with an `ExpressionAttributeNames` or `ExpressionAttributeValues` key over 255 bytes gets `ValidationException` "ExpressionAttributeNames contains invalid key: The expression attribute map contains a key that is too long; size of key: 256". 1.0.0 answered `SerializationException` with the same text after "Start of structure or map found where not expected: ". PutItem with an empty attribute name in `ExpressionAttributeNames` changes the same way: `ValidationException` "ExpressionAttributeNames contains invalid value: Empty attribute name for key #v", where 1.0.0 answered `SerializationException`. The `ExpressionAttributeValues` text now carries the same "; size of key: <n>" suffix as the names text; 1.0.0 left it off.
- On Scan, a `Limit` below 1, a `Segment` outside 0 to 999999 or a `TotalSegments` outside 1 to 1000000 is refused before the filter and projection expressions are read and before the table lookup, each field on its own: `TotalSegments: 0` without `Segment` gets "The parameter TotalSegments should be greater than or equal to 1", where 1.0.0 answered the missing `Segment`, and `Limit: 0` beside a filter syntax error or a missing table gets the `Limit` text, where 1.0.0 answered the syntax error or `ResourceNotFoundException`. The texts of these three ranges are 1.0.0's.

**Who is affected.** A client that sends an expression of more than 300 operators, which DynamoDB refuses: with 1.0.0 the request ran, with this release it gets `ValidationException` and nothing is read or written. A deployment that needs the old behaviour sets `max_expression_operators` under `[limits]` above its largest expression; DynamoDB has no such setting. A client that matches error texts: the syntax error texts and the PutItem key length error type change as listed above. No catalog migration is required, and a rollback to 1.0.0 brings back the old answers.

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.

"a rollback to 1.0.0 brings back the old answers" holds only for a configuration without max_expression_operators. With the key set, as line 400 suggests for the old behaviour, a 1.0.0 binary refuses to start: Error: unknown field 'max_expression_operators' (two runs). A sentence telling the reader to remove the key before rolling back would cover it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in ee1d541. The entry now ends: "Remove max_expression_operators from [limits] before such a rollback: 1.0.0 refuses to start with a configuration that holds the key." LimitsConfig in 1.0.0 carries #[serde(deny_unknown_fields)] and has no such field, which matches the two runs you made.

crates/core/src/expression/parser.rs grew to 702 lines, with the
inline test module from line 396. The module moves unchanged to
parser_tests.rs, which parser.rs names with #[path], as evaluator.rs and
key_condition.rs name theirs. parser.rs is now 398 lines. No test changes.
….0.0

The v1.1.0 entry said that a rollback to 1.0.0 brings back the old
answers. A configuration that sets max_expression_operators, as the entry
suggests for the old behaviour, stops a 1.0.0 binary at start: LimitsConfig
in 1.0.0 refuses unknown fields. The entry now says to remove the key
before such a rollback.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

On the file size item of your review of 24 Nov: ae298f4 moves the inline test module of crates/core/src/expression/parser.rs unchanged into parser_tests.rs. It names the file with #[path], as evaluator.rs and key_condition.rs name theirs. parser.rs goes from 702 lines to 398, and the 23 parser tests pass.

@demohan demohan 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.

The items from the earlier review are resolved at ee1d541.

  • parser.rs is 398 lines. The tests moved to parser_tests.rs byte for byte after the license header, lines 1 to 396 of parser.rs are unchanged, and the 23 tests run under the same path and pass. Changing an expectation in the moved file, or putting main's expected '(' back into the IN branch, fails the moved tests.
  • The rollback sentence holds on a v1.0.0 build from the tag: with max_expression_operators under [limits], serve exits 1 with unknown field `max_expression_operators` , and without the key it starts on the catalog this head wrote, reads back its items and runs a 151-term Scan as 1.0.0 did. Rolling forward again restores the 300-operator cap, and the init template keeps the key commented out.
  • The same 236 request shapes as the earlier round, sent twice to the service in us-east-1 and to this head, answer as at ab59fc2, and a 151-term PartiQL NOT SELECT answers The expression contains too many operators; operator count: 301 on both. fmt, clippy and the 1.91.1 check are clean, 1180 core tests pass, and CI is green on 64 of 64 checks.

The Files section of the PR body still gives parser.rs as 702 lines; the Changes section has the right count.

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

The Files section now gives parser.rs as 398 lines at ee1d541 (543 on main). This was a body edit only, so the head is still ee1d541.

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

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Condition expressions: three shapes the service refuses or words differently (measured 2026-10-24)

3 participants