Repository navigation
fix(expression): operator cap, syntax error wording, PutItem map keys - #558
LeeroyHannigan wants to merge 39 commits into
Conversation
…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.
… keyword text and the legacy count
… 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.
98fb237 to
077d435
Compare
demohan
left a comment
There was a problem hiding this comment.
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.
| if filter_maps.is_none() | ||
| && let Some(ref f) = filter | ||
| { | ||
| crate::expression_helpers::check_operator_count(f, ExpressionKind::Filter)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| // 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)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| .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)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /// | ||
| /// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| if filter_maps.is_none() | ||
| && let Some(ref f) = filter | ||
| { | ||
| crate::expression_helpers::check_operator_count(f, ExpressionKind::Filter)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 { | |||
There was a problem hiding this comment.
#v IN IN (:v) answers Syntax error; token: "IN", near: "IN IN (" on the service, and expected '(' here.
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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'.
There was a problem hiding this comment.
| } | ||
|
|
||
| #[test] | ||
| fn measured_update_syntax_errors() { |
There was a problem hiding this comment.
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.
| @@ -0,0 +1,997 @@ | |||
| // Copyright 2026 ExtendDB contributors | |||
There was a problem hiding this comment.
This file is 997 lines. Splitting it into parse, classify and resolve modules as pure moves would keep each under 600.
There was a problem hiding this comment.
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.
…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
left a comment
There was a problem hiding this comment.
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 < :banswer the BOOL operand error. 151 terms with:zzanswer the undefined value error.begins_withwith an N value answers the operand type error. Each matches the service, and each comes ahead of the count.Limit: 0andTotalSegments: 0also come ahead of the count. - PutItem, UpdateItem and DeleteItem: 151 terms with
:zzanswer 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 INand 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.
| - 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. |
There was a problem hiding this comment.
"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.
There was a problem hiding this comment.
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.
|
On the file size item of your review of 24 Nov: ae298f4 moves the inline test module of |
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier review are resolved at ee1d541.
parser.rsis 398 lines. The tests moved toparser_tests.rsbyte for byte after the license header, lines 1 to 396 ofparser.rsare unchanged, and the 23 tests run under the same path and pass. Changing an expectation in the moved file, or putting main'sexpected '('back into theINbranch, fails the moved tests.- The rollback sentence holds on a v1.0.0 build from the tag: with
max_expression_operatorsunder[limits],serveexits 1 withunknown 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: 301on 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.
Changes since the last review
The branch merges main at
8c643330c(d44387b) and adds six commits:TestPlaceholderKeyLengthintotests/test_expression_placeholder_key_length.py.TotalSegments: 0without a Segment now answers the TotalSegments range. Before this commit it answered the operator count or the missing Segment.Segment: -1without a TotalSegments answers the Segment range. The range rows assert their full texts, and the row s41 covers the new case.is_syntax_errorwith a typed fault from the condition parser,ConditionFault::SyntaxorConditionFault::Other. No answer changes.docs/manuals/07-upgrade-manual.md.# max_expression_operators = 300in the config template thatextenddb initwrites.After the review of 24 Nov, two more commits:
crates/core/src/expression/parser.rsunchanged intoparser_tests.rs.parser.rsgoes from 702 lines to 398.max_expression_operatorsbefore 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]settingmax_expression_operators, default 300. On PutItem, UpdateItem and DeleteItem the text matches the service after the1 validation error detected:prefix, which #399 adds.The count follows the service: every comparison operator,
AND,OR,NOT,BETWEEN,INand every function call (sizeincluded) counts one. Parentheses, paths, placeholders and the elements of anINlist count zero.BETWEEN :a AND :bcounts one, and its innerANDis not counted. Examples from the measurements:attribute_not_exists(pk)followed by 300OR #v = :vterms answers 601, 160#v BETWEEN :v AND :vterms joined byORanswer 319, and 230size(#v) = :vterms answer 689.It applies to
ConditionExpressionon PutItem, UpdateItem and DeleteItem, toFilterExpressionon Scan and Query, and toKeyConditionExpressionon Query. The legacyScanFilter,QueryFilterandExpectedparameters are not counted: the service accepts 160 conditions in each. AnUpdateExpressionhas no operator cap: a chain of arithmetic is a syntax error first, and 301SETassignments are accepted. TransactWriteItems is unchanged. The service counts it the same way as PutItem. A Put of 151, 200 or 300#v = :vterms 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_withprefix that is not S or B. It also refuses a literal that does not order in an ordering comparison or BETWEEN. The older checksvalidate_ordering_operand_typesandvalidate_begins_with_operandsstay 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 areNOTandORin a key condition, which the service answers withInvalid 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 = = :vanswerstoken: "=", near: "= = :v",#v==:vanswersnear: "==:v", and= #v = :vanswersnear: "= #v". When the expression ends where a token is required, the token is<EOF>and the window is the last token:#v = :v ANDanswerstoken: "<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 = :vanswersnear: " = #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 = :vanswerstoken: "and", near: "and and #v".Other syntax error texts are unchanged. The condition parser reports a syntax error as the
Syntaxvariant ofConditionFault. 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
ExpressionAttributeNamesorExpressionAttributeValues. 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
ExpressionAttributeValuestext 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
ExpressionAttributeNameson PutItem.{"#v": ""}answers ValidationExceptionExpressionAttributeNames contains invalid value: Empty attribute name for key #v. Main answers SerializationException with the same text afterStart of structure or map found where not expected:. The service answers ValidationException with the write prefix.Docs
docs/dynamodb-limits.mdlists the cap with the expression limits.docs/manuals/07-upgrade-manual.mdgets 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 namesmax_expression_operatorsas 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
1 validation error detected:. ExtendDB does not, on any check. fix(expressions): validate in the service's order, with its messages #399 adds the prefix.attribute_type(#v, :t)with a type name the service does not know,attribute_typewith an N value, andsize(:b)with a BOOL. Beside 151attribute_type(#v, :t)calls with:tthe S valuex, the service answersInvalid attribute type name found; type: x, valid types: {S,SS,N,NS,B,BS,BOOL,NULL,L,M}(measured 2026-11-23). This branch answers the count for all three. size() of a BOOL and attribute_type() with an N type are not refused before evaluation #1209 covers the two type faults and attribute_type with a type name outside the ten type codes is evaluated as false, and DynamoDB refuses the request #1040 the unknown type name.FilterExpressioncount. The service reports the count first. Take a table with HASHpk(S) and RANGEsk(S) and a filter of 301 operators (151#f = :pterms joined byOR).pk = :p AND sk = :nwith:nan N value answersOne or more parameter values were invalid: Condition parameter type does not match schema type, on this branch and on main.sk = :sanswersQuery condition missed key schema element: pkon both. The service answersInvalid FilterExpression: The expression contains too many operators; operator count: 301to both (measured 2026-10-31 and 2026-11-01). fix(query): check Query values against the key schema and the number rules #544 moves the type check after the filter checks, and the missing key check is Query: the missing key refusal comes before the filter syntax and unused value checks when the key condition has an equality #712.pk = :v AND10#v = :vterms joined by AND, withvoutside the key schema, answersKeyConditionExpressions must only contain one condition per keyon the service, before the table lookup. ExtendDB serves the request with no items, as on main. It accepts a key condition clause on an attribute outside the key schema, and the one-condition-per-key check that fix(query): classify and order key conditions on a multi-attribute GSI the way the service does #429 adds covers the key attributes. Query: shapes the service refuses that ExtendDB accepts or words differently (measured 2026-10-23) #489 records the non-key clause. The same shape with 150 terms answers the count on both.ScanFilterbeside aFilterExpressionwithLimit: 0answers the Limit range, as the service does. Main answersCan not use both expression and non-expression parameters in the same request: Non-expression parameters: {ScanFilter} Expression parameters: {FilterExpression}. The range checks now run before the parameter mixing checks.Syntax error; token:form. They are a doubled comma, a stray)or(, a placeholder where a connector is required, and the end of input after(. FilterExpression and ProjectionExpression syntax errors answer the parser's text, not the service's token and position #839 covers these for FilterExpression and ProjectionExpression. The same holds for some key condition and update shapes, such aspk = :p AND sk BETWEEN :a :bandSET #v #a = :v.NOTor 160 nested parenthesised groups: the service evaluates or counts them. ExtendDB stops at its nesting depth limit of 150 first, as on main.; expression size: <n>, the service does not.InternalServerError. The MongoDB filter compiler nests one level perORorAND, and the chain fails inside MongoDB. The test for that row is marked as an expected failure on MongoDB here. fix(mongodb): evaluate deeply nested conditions instead of answering 500 #571, stacked on this branch, evaluates such a condition in Rust and removes the marker.Files
key_condition.rsgrew to 2,029 lines andprojection.rsto 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]patternevaluator_tests.rsuses.crates/engine/src/query.rsis 800 lines on main and 754 here.crates/core/src/expression/parser.rsis 398 lines (543 on main),crates/engine/src/partiql/mod.rsis 689 (680 on main), and the test filestests/test_expression_operator_limits.pyandtests/test_expression_placeholder_key_length.pyare 605 and 151.Overlaps
Three open PRs add their own copies of checks this PR adds, and each conflicts with this branch:
check_path_refsincrates/core/src/expression/semantics/refs.rsandcheck_key_condition_refsincrates/engine/src/expression_helpers.rs. It conflicts incrates/core/src/expression/mod.rs,parser.rs,update_parser.rs,crates/engine/src/expression_helpers.rs,query.rsandscan.rs.crates/engine/src/query.rs.validate_scan_request_bodyand conflicts incrates/engine/src/scan.rsandcrates/core/src/expression/key_condition.rs(its conflict incrates/core/src/types/query.rsis with main's fix(engine): read an ExecuteStatement Limit from a JSON number #1144).Whichever PR merges second drops its copy:
validate_placeholders_and_operandshere against the reference checks of #399 and #479, andvalidate_scan_rangeshere againstvalidate_scan_request_bodyof #850.Rebase on #429
Rebased on main at
f49c5f82(#429), which includes #511. Both changedcrates/core/src/expression/key_condition.rs, and #511 also changed thepub useblock ofcrates/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_conditionintoparse_clauses, whichparse_key_conditionand its newkey_condition_clause_operandsboth call.parse_clausesnow takes the expression text and builds the syntax error window, so both callers report a repeated or misplaced operator or keyword in theSyntax error; token:form.parse_key_condition_frompasses the request's text.parse_key_conditionandkey_condition_clause_operandspass none, so their window joins the token texts. A unit test checks thatkey_condition_clause_operandsrefuses the same expressions asparse_key_condition, with the same error. Authorization callskey_condition_clause_operandsto finddynamodb:LeadingKeysand 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. Inmod.rsthe 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_schemaandfor_each_clauseto theimpl KeyConditionblock, and #429 and #511 added 20 tests to the test module. The whole block andresolve_path_attrgo tokey_condition_resolve.rs, and the whole test module goes tokey_condition_tests.rs.SortKeyCondition::path, which #429 added, stays next toSortKeyConditioninkey_condition.rs.key_condition.rswas 2,029 lines before the move and is 645 at this head.key_condition_resolve.rsis 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) andkey_condition_resolve_tests.rs(223).crates/engine/src/query.rsmerged without a conflict.handle_querycallsparse_key_condition_expr, which runs the key condition count, beforeresolve_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. TheFilterExpressioncount 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
374628096conflicts incrates/core/src/expression/key_condition.rs,crates/core/src/expression/mod.rs,crates/engine/src/expression_helpers.rsandcrates/engine/src/query.rs.parse_key_condition_expramaps: &ExpressionMapsargument in the second position, so its signature merges without a conflict. Its body keeps this branch's checks first: the condition grammar's syntax error, then the operator count with the placeholder and operand pass over the cap. fix(core): refuse a second condition on a key in KeyConditionExpression #484's parse with the maps comes after them.crates/engine/src/query/request_checks.rs, where it already passes the maps. The merge takes fix(core): refuse a second condition on a key in KeyConditionExpression #484's side of that call.impl KeyConditionblock tokey_condition_resolve.rs, so fix(core): refuse a second condition on a key in KeyConditionExpression #484's changes to that block go there.Whichever of #558 and #484 merges second resolves these files. #484 can then call
validate_placeholders_and_operandsin place of its own reference andbegins_withchecks.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's1 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 theSyntax error; token:wording.tests/expression_fault_helpers.pyholds the request helpers and the table fixture that the three files share.tests/test_legacy_filter_operator_count.py: a 160-conditionScanFilterandQueryFilterare answered normally and a 160-conditionExpectedis 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 updatedtest_value_key_too_long.crates/core/src/expressionandcrates/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 insidekey_condition_clause_operands, and aSyntaxfault 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.--libtests: 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. Atb4260658dthe four files then present passed on PostgreSQL (122), andtests/test_expression_operator_limits.pypassed against DynamoDB (66 in each of three runs on 2026-11-20). CI runs the rest, MongoDB and Cassandra included.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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,
Storagetrait, 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_operatorsunder[limits]above its largest expression. A client that matches error texts sees theSyntax 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.mdhas 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.