Skip to content

fix(partiql): give literal syntax errors and tuple keys the service's texts - #1398

Open
LeeroyHannigan wants to merge 1 commit into
fix/1383-insert-value-namesfrom
fix/887-literal-texts
Open

LeeroyHannigan wants to merge 1 commit into
fix/1383-insert-value-namesfrom
fix/887-literal-texts

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

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.

  • A missing colon is Expected COLON, a missing closing brace Expected RIGHT_CURLY, and a missing closing bracket Expected 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.
  • A key that is not a string is Tuple keys must be of type String. Actual type: <type> under <path> at <position>. 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 gives Not, and a minus sign before anything but a number gives Neg. A backtick literal gets the Ion text, Ion Literals are not supported: <type> under key root.
  • The path names the place of the map in the value. It is 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 (, and NOT and the minus sign at their own position.
  • A string in parentheses is a string key, and a repeated one is named at the string.
  • The key refusal waits for the statement to parse, so a syntax error anywhere comes first. Among the refusals in a value, the first one written is reported.
  • A first bag member that starts with {, [ or << gets the Bag refusal ahead of the refusals inside it.

The code:

  • crates/core/src/partiql/parser/literals.rs: item_map, map_members and list_elements give the measured texts. A new map_key replaces the key match that item_map and map_members each had, and key_refusal holds the one copy of the key text. map_key defers the refusal and reads the key to its end with the readers that exist. bag_members defers 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 of term_in_parentheses move into call_starts_here and refused_call, which map_key also 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 in limits/tests.rs uses maps as keys. The stack tests gain keys in parentheses and maps as keys.
  • The measured statements are one table in 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 in terms/tests.rs now expects Expected RIGHT_CURLY for 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 prefix Statement wasn't well formed, can't be processed: , and TK stands for Tuple keys must be of type String. Actual type: .

Statement DynamoDB ExtendDB at the base
INSERT INTO <T> VALUE {'pk' 'q'} not well formed: Expected COLON not well formed: Expected : in item value
INSERT INTO <T> VALUE {'pk': 'q' not well formed: Expected RIGHT_CURLY not well formed: Expected } to close item value
SELECT * FROM <T> WHERE a = [1, 2 not well formed: Expected RIGHT_BRACKET not well formed: Expected ] to close list literal
INSERT INTO <T> VALUE {1: 1} TK INT under root at 1:43:1 TK Id under root at 1:43:1
INSERT INTO <T> VALUE {1.5: 1} TK DECIMAL under root at 1:43:3 TK Id under root at 1:43:3
INSERT INTO <T> VALUE {true: 1} TK BOOL under root at 1:43:4 TK Id under root at 1:43:4
INSERT INTO <T> VALUE {a.b: 1} TK Path under root at 1:43:1 TK Id under root at 1:43:1
INSERT INTO <T> VALUE {'pk': 'q', 'm': {'n': {1: 1}}} TK INT under root.n at 1:66:1 TK Id under root at 1:66:1
INSERT INTO <T> VALUE {1: 1, 'c': } not well formed: Unexpected term TK Id under root at 1:43:1
INSERT INTO <T> VALUE {('a'): 1} ResourceNotFoundException, for the missing table TK Id under root at 1:43:1

The 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 test a_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 warnings and rustfmt are clean.
  • A SQLite release build of this commit matched DynamoDB on 309 of 344 measured statements. They include the 57 statements of fix(partiql): refuse quoted names and paths in literals as DynamoDB does #1393 and fix(partiql): read @ as an operator that takes a name #1386, which all match. The list below gives the 35 that differ.
  • 153 of the 344 are statements whose answer the change moves and that no table row covers. 128 of them now get DynamoDB's answer, and none moved away from it.
  • tests/test_partiql_grammar.py, tests/test_partiql_write.py and tests/test_partiql_unsupported_forms.py against that build: 1351 passed, 3 skipped.
  • The worst statement within the length limit needs about 15.6 MiB of stack on a debug build. The parse thread for a deep statement has 64 MiB.

These forms still differ from DynamoDB:

  • a key whose root is an operator, such as 'a' + 'b', 'a' || 'b', a IS NULL, NOT a = 1 or NOT a AND b. DynamoDB names the operator at its position, and the parser does not record it.
  • a key that is a path after a literal, a string or a call, such as true.a or 'a'.b
  • a key that is a path with an expression or a : in its brackets
  • a key that is a quoted call, count(*), or a backtick literal after a minus sign
  • a number refusal written before a key refusal, as in {'pk': 1e126, 1: 1}
  • the order of a bag's own refusals and a later syntax error, which PartiQL (#411): for a statement with two faults, the first refusal differs from DynamoDB, and so does the number set text #886 covers
  • <<>>> as a value, a LIMIT after an UPDATE, a query in IN and a bag INSERT

Production is +187 -72 lines over the base, and the tests are +449 -11.

Checklist

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

ADR / RFC: n/a


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

… 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 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.

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 => {

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 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() => {

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.

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(_) => {

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.

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

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.

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

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.

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>> {

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.

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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants