Repository navigation
fix(partiql): give literal syntax errors and tuple keys the service's texts - #1398
LeeroyHannigan wants to merge 1 commit into
Conversation
… texts
Amazon DynamoDB answers a PartiQL map member without its colon with
"Expected COLON". A map without its closing brace gets "Expected
RIGHT_CURLY", and a list without its closing bracket "Expected
RIGHT_BRACKET". The texts are the same in an INSERT item, a map or a list
in it, a SET value and a WHERE literal.
DynamoDB refuses a map key that is not a string as "Tuple keys must be of
type String. Actual type:" and the key's type. A number is INT or DECIMAL.
The words true and false are BOOL, null is NULL and missing is Missing. A
map, a list and a bag are Struct, List and Bag. A parameter, a name, a
path and a call are Parameter, Id, Path and Call. NOT makes the key Not,
and a minus sign before anything but a number makes it Neg.
The text names the place of the map in the value: root for the item and
for a value's own map, and root.n or root[0] for a map inside it. The
position is that of the key's first token after any signs, parentheses
and @. A list in parentheses is refused at its opening parenthesis. NOT
and the minus sign are refused at their own position. A string in
parentheses is a string key, and a repeated one is named at the string.
The refusal waits until the statement parses, so a syntax error anywhere
comes first. Among the refusals in a value, such as a duplicate key, the
first one written is reported. A map as the first member of a bag gets
the Bag refusal, ahead of the refusal of its key.
DynamoDB was measured in us-east-1 on 23 November 2026 with
ExecuteStatement on a table that does not exist. Each statement went out
twice and got the same answer both times.
ExtendDB answered the three syntax errors with texts of its own, such as
"Expected : in item value". It refused every key that is not a string as
an Id under root, before it read the rest of the statement.
In literals.rs, item_map, map_members and list_elements give the measured
texts. map_key replaces the key match that item_map and map_members each
had. It returns a string key, also one in parentheses. For another key it
defers the refusal and reads the key to its end, so the parse goes on. It
reads a number with signed_number, a map, a list or a bag with
literal_value, and a name or a path with path. A backtick literal goes
through unsigned_atom, which defers its Ion text. The operand after NOT or
a minus sign goes through operand. The duplicate key check runs for string
keys only, at inner_span. bag_members defers the Bag refusal of a first
member that starts with {, [ or << before it reads the member. In
predicates.rs, the call check and the call reading of term_in_parentheses
move into call_starts_here and refused_call, which map_key also calls.
A key whose root is an infix operator, such as 'a' + 'b', gets "Expected
COLON". DynamoDB names that operator as the key's type, and the parser
does not record it.
The measured statements are one table in parser/tests/values.rs, which
shares its row check with the table of names and paths. The at-sign table
in terms/tests.rs expects "Expected RIGHT_CURLY" for an item value of
@foo(b). The stack tests gain keys in parentheses and maps as keys. A map
read as a key takes about twice the stack per level of a map value, so
the worst parse in limits/tests.rs uses maps as keys, and the limits.rs
comment gives the new figures.
Part of #887
demohan
left a comment
There was a problem hiding this comment.
Literal syntax errors and tuple keys get the service's texts at e2cba80 in the forms the table covers, and nothing the base answered as the service does moved away from it. Of 362 statements sent twice to us-east-1 and to this head and its base, this head matches the service byte for byte on 278, no statement is accepted on one side and refused on the other, and 104 of the table's 111 rows match the service (the other 7 are the operator keys the body lists). A string key in parentheses parses and stores the same item as the service. worst() needs 16,444 KB of stack on a debug build, under the 32 MiB the test gives it. Nine of nine controls fail as they should, fmt, clippy, the core and engine lib tests (1154 and 870 passed), the 1.91.1 check and the three PartiQL pytest files against this head (1351 passed) are clean, CI is green on 59 of 59, and it merges onto main at d4dd0ba without conflict, where the build, the core lib tests (1250) and the 1.94.0 check pass.
Several key forms that the base refused with the tuple key text now get a syntax error or a nesting cap, and a few others name the wrong type or path (below). I will approve once these give the service's text, with rows in the table.
| TokenKind::Ion(_) => { | ||
| self.unsigned_atom(&at)?; | ||
| } | ||
| TokenKind::Minus => { |
There was a problem hiding this comment.
The minus and NOT arms read the rest with operand(), which does not read NOT, so INSERT INTO <T> VALUE {NOT NOT a: 1}, {NOT NOT 'a': 1}, {NOT NOT NOT a: 1}, {-NOT a: 1}, the same in a nested map and UPDATE <T> SET a = {NOT NOT a: 1} get Statement wasn't well formed, can't be processed: Unexpected operator here, where the service gives Tuple keys must be of type String. Actual type: Not under root at 1:42:3 (Neg ... at 1:42:1) and the base gave the tuple key text with Id. And a refused key read with the counting readers meets the caps where the service gives the outermost key's refusal at every depth measured: after SELECT * FROM <T> WHERE a = , {- 100 deep (also 101 to 1001) gets Actual type: Neg under root at 1:48:1 on the service, {NOT 100 deep Not ... at 1:48:3, {size( 100 deep Call ... at 1:48:4, { 1001 deep Struct ... at 1:48:1 and {[ 1000 deep List ... at 1:48:1, and each gets expression nesting depth exceeded here (the base answered Id; at 2, 33 and 99 levels this matches). Reading the run of NOT and minus before the operand, and reporting the deferred key refusal when a cap is met inside the key (or reading the rest of a refused key without counting, as rest_of_path_in_brackets does), would match.
| self.bump(); | ||
| self.operand()?; | ||
| } | ||
| _ if self.call_starts_here() => { |
There was a problem hiding this comment.
CAST starts a call, so refused_call reads it with call_args and fails at AS: {CAST(1 AS INT): 1}, {CAST('a' AS STRING): 1}, the same nested, and {(CAST(1 AS INT)): 1} get Expected RIGHT_PAREN here and Tuple keys must be of type String. Actual type: Cast under root at 1:42:4 (1:59:4, 1:43:4) on the service; the base gave the tuple key text at the right position. Reading a CAST key with the CAST reader and deferring Cast would match.
| self.bump(); | ||
| self.take_param_index(); | ||
| } | ||
| TokenKind::Ion(_) => { |
There was a problem hiding this comment.
unsigned_atom writes under key root for an Ion literal, so a backtick key in a nested map names the wrong path: {'pk': 'q', 'm': {'n': {1: 1}}} gets Ion Literals are not supported: INT under key root.n at 1:65:3 on the service and under key root here; SET a = {'x': {1: 1}} gets root.x, a key in a list root[0], and {'n': {'o': {"s": 1}}} STRING under key root.n.o there. The rows cover only maps at root, and the body and the doc comment give the text as under key root.
| } else if first && self.at_name_in_literal() { | ||
| self.defer(&refusal); | ||
| self.path()?; | ||
| } else if first |
There was a problem hiding this comment.
Only a bare first member that starts with {, [ or << keeps the Bag refusal ahead of what it holds. <<1, {1: 1}>>, <<1, {true: 1}>>, <<1, [{1: 1}]>> and SET a = <<1, {1: 1}>> get Unsupported data type in Bag. DynamoDB only supports either numbers or strings in bags with no position on the service, and the key refusal here (Actual type: INT under root at 1:64:1, BOOL, root[0]); <<({1: 1})>> gets the Bag text at 1:61:1 there and the key refusal at 1:62:1 here. The body says the first refusal written is reported. Deferring the Bag refusal ahead of every member that starts with {, [, << or (, with no position after the first, would match.
| "INSERT INTO <T> VALUE {1: 1, 'pk': 'q', 'pk': 'r'}", | ||
| key("INT under root at 1:43:1"), | ||
| ), | ||
| // The service names an expression key by its root operator (`Plus |
There was a problem hiding this comment.
These seven rows assert Expected COLON where the service gives Tuple keys must be of type String. Actual type: Plus under root at 1:46:1 for {'a' + 'b': 1}, Plus ... 1:44:1 for {1 + 1: 1}, and Eq, Concat, Like and IsType ... 1:44:2 ({a IS NULL: 1}) for the others, so the table holds answers the service does not give; for {1 + 1: 1} and {a IS NULL: 1} the base gave the tuple key text. Nearby, {(1 + 1): 1} and {('a' || 'b'): 1} get Expected RIGHT_PAREN (service Plus ... 1:45:1, Concat ... 1:47:2), {('a').b: 1} and {size(a).b: 1} Expected COLON (service Path under root), and where a number overflow comes before a bad key ({'pk': 1e126, 1: 1}) the service reports the overflow and this the key. The body lists these. Recording the key expression's root operator and refusing with its name would match.
| /// `{'pk': 'q', 'm': {1: 1}}` is under root), and `root.n` or `root[0]` | ||
| /// for a map inside it (measured 2026-11-23 with `{'m': {'n': {1: 1}}}`, | ||
| /// `[{1: 1}]` and `SET a = {'x': {1: 1}}`). | ||
| fn map_key(&mut self, path: &str) -> PResult<Option<String>> { |
There was a problem hiding this comment.
Optional. The doc comment says any other token is refused at once as an Id, but the service gives syntax errors for those: {SELECT: 1}, {FROM: 1}, {*: 1}, {.: 1}, {: 1} and {;: 1} get Unexpected term, {=: 1} Unexpected operator and {value: 1} Unexpected keyword, as on the base.
What
PartiQL now gives a literal with a missing colon or closing token, and a map key that is not a string, the texts DynamoDB gives.
Expected COLON, a missing closing braceExpected RIGHT_CURLY, and a missing closing bracketExpected RIGHT_BRACKET. These texts are the same in an INSERT item, a map or a list in it, a SET value and a WHERE literal.Tuple keys must be of type String. Actual type: <type> under <path> at <position>. A number isINTorDECIMAL. The words true and false areBOOL, null isNULLand missing isMissing. A map, a list and a bag areStruct,ListandBag. A parameter, a name, a path and a call areParameter,Id,PathandCall.NOTgivesNot, and a minus sign before anything but a number givesNeg. A backtick literal gets the Ion text,Ion Literals are not supported: <type> under key root.rootfor the item and for a value's own map, androot.norroot[0]for a map inside it.@. A list in parentheses is refused at its(, andNOTand the minus sign at their own position.{,[or<<gets the Bag refusal ahead of the refusals inside it.The code:
crates/core/src/partiql/parser/literals.rs:item_map,map_membersandlist_elementsgive the measured texts. A newmap_keyreplaces the key match thatitem_mapandmap_memberseach had, andkey_refusalholds the one copy of the key text.map_keydefers the refusal and reads the key to its end with the readers that exist.bag_membersdefers the Bag refusal of such a first member before it reads it.crates/core/src/partiql/parser/predicates.rs: the call check and the call reading ofterm_in_parenthesesmove intocall_starts_hereandrefused_call, whichmap_keyalso calls.crates/core/src/partiql/parser/limits.rs: a map read as a key takes about twice the stack per level of a map value. The module comment gives the new figures, and the worst parse inlimits/tests.rsuses maps as keys. The stack tests gain keys in parentheses and maps as keys.parser/tests/values.rs,literal_syntax_errors_and_tuple_keys. It shares its row check with the table of fix(partiql): refuse quoted names and paths in literals as DynamoDB does #1393. The at-sign table of fix(partiql): read @ as an operator that takes a name #1386 interms/tests.rsnow expectsExpected RIGHT_CURLYfor the item value@foo(b).The base of this PR is #1393.
Part of #887
Why
DynamoDB was measured in us-east-1 on 23 November 2026 with ExecuteStatement on the table
"ets-parityat-missing", which does not exist. Each statement went out twice, with the same answer both times. The positions count that table name.<T>is the table name with its quotes, "not well formed" stands for the prefixStatement wasn't well formed, can't be processed:, and TK stands forTuple keys must be of type String. Actual type:.INSERT INTO <T> VALUE {'pk' 'q'}Expected COLONExpected : in item valueINSERT INTO <T> VALUE {'pk': 'q'Expected RIGHT_CURLYExpected } to close item valueSELECT * FROM <T> WHERE a = [1, 2Expected RIGHT_BRACKETExpected ] to close list literalINSERT INTO <T> VALUE {1: 1}INT under root at 1:43:1Id under root at 1:43:1INSERT INTO <T> VALUE {1.5: 1}DECIMAL under root at 1:43:3Id under root at 1:43:3INSERT INTO <T> VALUE {true: 1}BOOL under root at 1:43:4Id under root at 1:43:4INSERT INTO <T> VALUE {a.b: 1}Path under root at 1:43:1Id under root at 1:43:1INSERT INTO <T> VALUE {'pk': 'q', 'm': {'n': {1: 1}}}INT under root.n at 1:66:1Id under root at 1:66:1INSERT INTO <T> VALUE {1: 1, 'c': }Unexpected termId under root at 1:43:1INSERT INTO <T> VALUE {('a'): 1}Id under root at 1:43:1The test table holds 111 rows. 104 are measured statements of these kinds, with DynamoDB's answers. The other seven are keys with an operator, which keep the answer this change gives.
Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1154 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 869 passed and 1 failed. The failure is the backup timing testa_retry_waits_on_its_registration_and_another_backup_is_refused, which passed 3 of 3 runs alone and does not call the parser.cargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warningsand rustfmt are clean.tests/test_partiql_grammar.py,tests/test_partiql_write.pyandtests/test_partiql_unsupported_forms.pyagainst that build: 1351 passed, 3 skipped.These forms still differ from DynamoDB:
'a' + 'b','a' || 'b',a IS NULL,NOT a = 1orNOT a AND b. DynamoDB names the operator at its position, and the parser does not record it.true.aor'a'.b:in its bracketscount(*), or a backtick literal after a minus sign{'pk': 1e126, 1: 1}<<>>>as a value, a LIMIT after an UPDATE, a query in IN and a bag INSERTProduction is +187 -72 lines over the base, and the tests are +449 -11.
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
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.