Skip to content

fix(partiql): refuse quoted names and paths in literals as DynamoDB does - #1393

Open
LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/1383-insert-value-names
Open

LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/1383-insert-value-names

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

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.

  • As the whole INSERT item value, "b" gets Unsupported data type: b under key root at <position>. A path such as b.c, b[0] or "b".c gets Unsupported data type: PATH under key root at <position>.
  • Inside a map or a list, a quoted name gets Id and a path gets Path, under the place of the member, such as root.x or root[0]. This holds in an INSERT value, a SET value and a WHERE condition.
  • A first bag member that is not a number or a string gets 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 own Id or Parameter refusal.
  • Each position is that of the first step, and a quoted name's position counts its quotes.
  • These refusals wait for the statement to parse, so a syntax error later in the statement comes first.
  • Where a value should start, }, ], ), >>, a comma and empty parentheses get Statement wasn't well formed, can't be processed: Unexpected term. In the brackets of a path, a }, ], ), >> or comma gets the same text.
  • In a bag after IN, a quoted name is a path, as a name is.

The code:

  • crates/core/src/partiql/parser/literals.rs: at_name_in_literal takes a quoted name and a path, and refuse_name_in_literal reads them with the path reader. item_map names the whole item value by its name or PATH. bag_members gives the Bag text to the first member only. literal_value answers a closing token with term_error.
  • crates/core/src/partiql/parser/predicates.rs: term_in_parentheses calls refuse_name_in_literal and drops its own copy of the Id and Path choice.
  • crates/core/src/partiql/parser/paths.rs: bracket_step answers a closing token with term_error.
  • The measured statements are one table in 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 prefix Statement wasn't well formed, can't be processed: , and the Bag text for Unsupported data type in Bag. DynamoDB only supports either numbers or strings in bags.

Statement DynamoDB ExtendDB at the base
INSERT INTO <T> VALUE {'pk': 'q', 'a': "b"} Unsupported data type: b under key root at 1:59:3 not well formed: Expected a literal value
INSERT INTO <T> VALUE {'pk': 'q', 'a': b.c} Unsupported data type: PATH under key root at 1:59:1 not well formed: Expected a literal value
INSERT INTO <T> VALUE {'pk': 'q', 'a': {'x': "b"}} Unsupported data type: Id under key root.x at 1:65:3 not well formed: Expected a literal value
UPDATE <T> SET a = [b.c] WHERE pk = 'q' Unsupported data type: Path under key root[0] at 1:40:1 not well formed: Expected a literal value
SELECT * FROM <T> WHERE a = ["b"] Unsupported data type: Id under key root[0] at 1:49:3 not well formed: Expected a literal value
INSERT INTO <T> VALUE {'pk': 'q', 's': <<a>>} the Bag text at 1:61:1 Unsupported data type: Id under key root at 1:61:1
INSERT INTO <T> VALUE {'pk': 'q', 's': <<1, a>>} Unsupported data type: Id under key root at 1:64:1 the same
INSERT INTO <T> VALUE {'pk': 'q', 'a': "b", 'c': } not well formed: Unexpected term not well formed: Expected a literal value
INSERT INTO <T> VALUE {'pk': 'q', 'l': [1, , 2]} not well formed: Unexpected term not well formed: Expected a literal value
SELECT * FROM <T> WHERE m[} = 1 not well formed: Unexpected term Unexpected path component at the }

The test table holds 79 measured rows of these kinds.

Testing done

  • On the commit: cargo test -p extenddb-core --lib --no-fail-fast gave 1153 passed and 1 ignored. cargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warnings and rustfmt are clean.
  • With the production code of the base, 61 of the first 67 rows of the table fail.
  • A SQLite release build of the commit before its last amendment answered the measured statements as DynamoDB does, except for these rows:
  • The last amendment moved bracket_step to at_closing_token and added 12 measured rows to the unit table.
  • tests/test_partiql_grammar.py, tests/test_partiql_write.py and tests/test_partiql_unsupported_forms.py against 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:

  • a name or a path in parentheses as the whole item value: (b) is Unsupported data type: b under key root
  • a path that starts with a literal: true.x is PATH
  • a call as a value: [foo(1)] is Call under key root[0]

Production is +102 -75 lines over the base, and the tests are +252 -8.

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.

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

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 {

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

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.

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()),

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

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

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