Repository navigation
fix(partiql): refuse quoted names and paths in literals as DynamoDB does - #1393
LeeroyHannigan wants to merge 1 commit into
Conversation
Amazon DynamoDB refuses a quoted name or a path as a PartiQL INSERT item value, as it refuses a name. As the whole item value, "b" gets "Unsupported data type: b under key root". A path such as b.c, b[0] or "b".c gets "Unsupported data type: PATH under key root". Inside a map or a list, in an INSERT value, a SET value or a WHERE condition, they are refused as Id and Path. The text names the key as their place in the value, such as root.x or root[0]. As the first member of a bag they get "Unsupported data type in Bag. DynamoDB only supports either numbers or strings in bags". After a number or a string in a bag, a name or a parameter gets its own Id or Parameter refusal. Each refusal gives the position of the first step, and a quoted name's position counts its quotes. A refusal is reported once the statement parses, so a syntax error later in the statement comes first. The same order holds for a bag member such as true. Where a value should start, a token that closes a value or separates two is "Statement wasn't well formed, can't be processed: Unexpected term". The measured cases are }, ], ), >>, a comma and empty parentheses. In the brackets of a path, a }, ], ), >> or comma gets that text too, in a condition, a SET target, a REMOVE, the select list and a value. In a bag after IN, a quoted name is a path, as a name is. 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 a quoted name and a path with "Statement wasn't well formed, can't be processed: Expected a literal value". It refused a name in a bag as an Id, and a parameter after a number with the Bag text. It refused true in a bag before it read the rest of the statement. It gave each of those tokens where a value starts the "Expected a literal value" text. In literals.rs, at_name_in_literal now also takes a quoted name and a path. refuse_name_in_literal reads them as paths and refuses them as Id or Path. item_map calls it for the whole item value, which it names by the name or PATH. term_in_parentheses in predicates.rs calls it for a quoted name and a path in a list in parentheses, in place of its own copy. bag_members defers the Bag refusal of a first member that is not a number or a string, as it did for a parameter, and reads a name, a quoted name or a path there with the path reader. It reads a later member with literal_value. literal_value and bracket_step in paths.rs answer a token that at_closing_token accepts with term_error. They reuse path_starts_here from paths.rs and token_text from terms.rs. Fixes #1383
demohan
left a comment
There was a problem hiding this comment.
A quoted name or a path in a literal now gets the service's refusal at e8f7108 in the forms the table covers, and nothing the base answered as the service does moved away from it. Of 546 statement shapes sent twice to us-east-1 as ExecuteStatement and ExecuteTransaction, 570 of the 1,092 answers moved from the base's to the service's, and no shape was accepted on one side and refused on the other. A path in a bag after IN (a IN <<b.c>>) now runs: on a table that exists, 14 SELECT, UPDATE and DELETE statements with it return what the service returns. Eleven of twelve controls fail as they should, the core lib tests (1153 passed), fmt and clippy 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 (1249 passed), clippy and the 1.94.0 check pass.
Four nearby forms now get a refusal the service does not give, where the base gave a syntax error (below). I will approve once those give the service's text and a test holds a path in a bag after IN.
| } else if first && self.at_name_in_literal() { | ||
| self.defer(&refusal); | ||
| self.path()?; | ||
| } else { |
There was a problem hiding this comment.
The service refuses a bag member that is not a number or string with Unsupported data type in Bag. DynamoDB only supports either numbers or strings in bags at the member's first token, ahead of anything inside it; here the member is read first, so what it holds wins. In INSERT INTO <T> VALUE {'pk': 'q', 's': ...}: <<{'x': "b"}>> gets the Bag text at 1:60:1 on the service and Unsupported data type: Id under key root.x at 1:66:3 here; <<{'x': b.c}>>, <<[b.c]>> and <<(a.b)>> get Path under key ... here; <<("a")>> gets Id under key root at 1:61:3 (service: Bag at 1:61:3); <<<<b>>>> gets the Bag text at 1:62:1 (service 1:60:2); and <<1, {'x': b.c}>> gets Path under key root.x (service: Bag, no position). A SET value and a WHERE literal answer the same. Keeping the Bag refusal before reading a first member that starts with {, [, ( or <<, as this does for a name, would match. The comment at line 183 says a member that is neither a number nor a string is refused at its first token; after the first member the service gives no position (<<1, true>>), as on the base.
| // literals: `{'pk': }`, `[}`, `[1, , 2]`, `[)]`, `{'x': )}`, | ||
| // `<<1,>>`, `{'x': >>}`, `[,]` and `()` are "Unexpected term") | ||
| _ if self.at_closing_token() => Err(self.term_error()), | ||
| TokenKind::Ident(name) => { |
There was a problem hiding this comment.
As the whole item value, a quoted name or path in parentheses now gets Id or Path where the service gives the name or PATH, though the body lists these among the forms not changed: {'pk': 'q', 'a': ("b")} gets Unsupported data type: Id under key root at 1:59:3 here and Unsupported data type: b under key root at 1:59:3 on the service; (@"b") and (("b")) likewise; (b.c), (b[0]) and (@b.c) get Path under key root here and PATH under key root there. The base gave Expected a literal value. Inside a map or list, [("b")] and [(b.c)] already match. Carrying whole through literal_in_parentheses when the parentheses are the whole value would fix these and (b).
| // brackets, as in `m[} = 1`, `m[) = 1`, `SET m[} = 1`, `REMOVE | ||
| // m[}`, `SELECT m[}` and `b[,]` in an INSERT value, are | ||
| // "Unexpected term") | ||
| _ if self.at_closing_token() => Err(self.term_error()), |
There was a problem hiding this comment.
Only the closing tokens go to term_error(), so :, ; or the end of the statement in a path's brackets inside a literal now gets the deferred name refusal: {'pk': 'q', 'a': b[:]}, b[;] and b[ at the end get Unsupported data type: PATH under key root at 1:58:1, [b[:]] gets Path under key root[0], <<a[:]>> the Bag text, and WHERE a IN <<b[:]>> gets Unexpected path component at 1:52:1; the service gives Statement wasn't well formed, can't be processed: Unexpected term for each, and the base gave Expected a literal value. Outside a literal (WHERE m[: = 1) these were already Unexpected path component on the base, where the service also says Unexpected term. Answering every token that cannot start a step with term_error() would match all of them.
| } else if let TokenKind::Ident(w) = &self.peek().kind | ||
| && self.at_name_in_literal(w) | ||
| { | ||
| } else if self.at_name_in_literal() { |
There was a problem hiding this comment.
Two things. An INSERT with no VALUE whose bag holds a path now gets the path's refusal ahead of the service's Unsupported operation: Inserting multiple items in a single statement is not supported, use "INSERT INTO tableName VALUE item" instead (statements.rs:382-397): INSERT INTO <T> <<"">> and <<a."">> get Path component cannot be an empty string, <<a[-1]>> gets List index is not within the allowable range; index: [-1] at 1:40:1, and <<a[1.5]>>, <<a[?]>> and <<a.*>> get Unexpected path component; a syntax error in the items still comes first on the service (<<a[:]>> is Unexpected term). And no test holds that a path in a bag after IN is an operand: with this branch limited to non-paths (&& !self.path_starts_here()) the 269 partiql tests pass and a IN <<b.c>> is refused where the service runs it. Rows for a IN <<m.b, 1>>, <<m[0]>> and <<"m".b>>, and INSERT INTO "t" <<a.b>>, would hold it, and the body does not mention that this now runs.
What
PartiQL now refuses a quoted name or a path in a literal as DynamoDB does. Where a value should start, a token that closes a value or separates two now gets
Unexpected term."b"getsUnsupported data type: b under key root at <position>. A path such asb.c,b[0]or"b".cgetsUnsupported data type: PATH under key root at <position>.Idand a path getsPath, under the place of the member, such asroot.xorroot[0]. This holds in an INSERT value, a SET value and a WHERE condition.Unsupported data type in Bag. DynamoDB only supports either numbers or strings in bags. This includes a name, a quoted name and a path. After a number or a string, a name or a parameter gets its ownIdorParameterrefusal.},],),>>, a comma and empty parentheses getStatement wasn't well formed, can't be processed: Unexpected term. In the brackets of a path, a},],),>>or comma gets the same text.The code:
crates/core/src/partiql/parser/literals.rs:at_name_in_literaltakes a quoted name and a path, andrefuse_name_in_literalreads them with the path reader.item_mapnames the whole item value by its name orPATH.bag_membersgives the Bag text to the first member only.literal_valueanswers a closing token withterm_error.crates/core/src/partiql/parser/predicates.rs:term_in_parenthesescallsrefuse_name_in_literaland drops its own copy of the Id and Path choice.crates/core/src/partiql/parser/paths.rs:bracket_stepanswers a closing token withterm_error.parser/tests/values.rs,names_paths_and_closing_tokens_in_literals.The base of this PR is #1386, which makes
@a token of its own.Fixes #1383
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. "Not well formed" stands for the prefixStatement wasn't well formed, can't be processed:, and the Bag text forUnsupported data type in Bag. DynamoDB only supports either numbers or strings in bags.INSERT INTO <T> VALUE {'pk': 'q', 'a': "b"}Unsupported data type: b under key root at 1:59:3Expected a literal valueINSERT INTO <T> VALUE {'pk': 'q', 'a': b.c}Unsupported data type: PATH under key root at 1:59:1Expected a literal valueINSERT INTO <T> VALUE {'pk': 'q', 'a': {'x': "b"}}Unsupported data type: Id under key root.x at 1:65:3Expected a literal valueUPDATE <T> SET a = [b.c] WHERE pk = 'q'Unsupported data type: Path under key root[0] at 1:40:1Expected a literal valueSELECT * FROM <T> WHERE a = ["b"]Unsupported data type: Id under key root[0] at 1:49:3Expected a literal valueINSERT INTO <T> VALUE {'pk': 'q', 's': <<a>>}Unsupported data type: Id under key root at 1:61:1INSERT INTO <T> VALUE {'pk': 'q', 's': <<1, a>>}Unsupported data type: Id under key root at 1:64:1INSERT INTO <T> VALUE {'pk': 'q', 'a': "b", 'c': }Unexpected termExpected a literal valueINSERT INTO <T> VALUE {'pk': 'q', 'l': [1, , 2]}Unexpected termExpected a literal valueSELECT * FROM <T> WHERE m[} = 1Unexpected termUnexpected path componentat the}The test table holds 79 measured rows of these kinds.
Testing done
cargo test -p extenddb-core --lib --no-fail-fastgave 1153 passed and 1 ignored.cargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warningsand rustfmt are clean.<<>>>), a bag in a select list and a LIMIT after an UPDATEbracket_steptoat_closing_tokenand added 12 measured rows to the unit table.tests/test_partiql_grammar.py,tests/test_partiql_write.pyandtests/test_partiql_unsupported_forms.pyagainst that build: 1351 passed, 3 skipped.These forms are not changed here. Each has a measured answer from DynamoDB, and they go into an issue of their own:
(b)isUnsupported data type: b under key roottrue.xisPATH[foo(1)]isCall under key root[0]Production is +102 -75 lines over the base, and the tests are +252 -8.
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.