Repository navigation
fix(partiql): read @ as an operator that takes a name - #1386
LeeroyHannigan wants to merge 1 commit into
Conversation
In PartiQL, Amazon DynamoDB reads @ as an operator that must have a name
after it. The name is an unquoted word that is not reserved, or a quoted
name. White space may come between @ and the name. Anything else after @,
the end of the statement included, gets "Statement wasn't well formed,
can't be processed: Identifier must follow @-operator".
The operand is the path whose first step is the name. A ( after the name
does not start a call. In the select list the list ends there. In a
condition or a SET value the ( is a token after the expression. After the
name in an INSERT item value or a list in parentheses, DynamoDB expects the
closing brace or parenthesis. A refusal of the operand gives the position
of the name after the @. A table name after FROM can start with @. The
table of UPDATE, DELETE and INSERT, a SET or REMOVE target and the step
after a dot do not take @. These positions refuse @ with the texts they
give any token that is not a name. Brackets in a SET or REMOVE target
refuse @ as they refuse a path.
DynamoDB was measured in us-east-1 on 23 November 2026 with ExecuteStatement
on tables that do not exist. Each statement went out twice and got the same
answer both times.
The PartiQL lexer read @ before a word as the word, and failed on @ before
any other character. It now gives @ a token of its own.
One parser function, eat_at_sign in parser.rs, reads the @ and refuses
anything but a name after it. path, parse_from_source, item_map and
literal_value call it, for the select list, ORDER BY, a FROM table and a
literal value. unsigned_atom reads an operand that starts with @ through
path. in_list, in_bag, bracket_step and term_in_parentheses call it for
the operand after IN, a bag after IN, brackets in a path and a list in
parentheses. The two map key positions call it before they refuse a key
that is not a string, so {@1: 1} gets the @ text. The ORDER BY list
reads another term after a comma when @ follows the comma. span and
inner_span step past an @, so a refusal gives the position of the name.
at_term_start counts @ as the start of a term, for the arguments of an
EXEC form.
Fixes #1382
demohan
left a comment
There was a problem hiding this comment.
@ is read as an operator that must have a name after it at 5366028, and no answer moved away from the service. Of 399 requests sent twice to us-east-1 and to this head, its base and main, this head gives the service's answer on 337, the base on 123 and main on 122, and none that the base or main answered as the service does changed. Every measured claim in the new comments matches the service, and the body's test and line counts reproduce. Twenty-one of 22 controls fail as they should, the new tests fail 63 of 89 rows on the base's code and the six new Python rows fail on the base server; fmt, clippy, the 1.91.1 check and the core and engine lib tests (1152 and 870 passed) are clean, CI is green on 59 of 59, and it merges onto main at d4dd0ba without conflict, where the build, the core and engine lib tests (1248 and 978) and the 1.94.0 check pass and all 399 requests answer as here.
Two positions still do not read the @ (below). I will approve once INSERT VALUE and LIMIT refuse a @ with no name as the service does and place a name after it at the name.
crates/core/src/partiql/parser/statements.rs:362
INSERT VALUE does not read a @ before the { check. INSERT INTO <T> VALUE @, VALUE @{'pk': 'q'}, VALUE @ {'pk': 'q'}, @1, @'a', @[1], @@a, @? and @size(a) get Statement wasn't well formed, can't be processed: Identifier must follow @-operator on the service, and Unsupported format in item expression at 1:43 here (the base gave an empty text). VALUE @a, @abc and @ "abc" already match, since the span skips the @. Calling eat_at_sign() after VALUE would match, with rows for VALUE @, VALUE @{'pk': 'q'} and VALUE @1.
crates/core/src/partiql/parser.rs:373
The LIMIT arm reads the token after LIMIT directly. ... WHERE pk = 'q' LIMIT @, LIMIT @1, LIMIT @size(a), SELECT * FROM <T> LIMIT @1 and WHERE @a = 1 LIMIT @ get Identifier must follow @-operator on the service and Unsupported clause: LIMIT here; with a name, the service places the refusal at the name and this at the @: LIMIT @a is 1:60:1 there and 1:59:1 here, LIMIT @ a 1:61:1 against 1:59:1, and LIMIT @"a" 1:60:3 against 1:59:1. The body says a refusal gives the position of the name. #1406 also changes this arm.
| self.defer_bracket("Path component cannot be an empty string"); | ||
| } | ||
| Ok((PathStep::Attribute(name), true)) | ||
| Ok((PathStep::Attribute(name), !at_sign)) |
There was a problem hiding this comment.
Optional. Nothing holds !at_sign here: with true in its place the 268 partiql tests pass. UPDATE <T> SET m[@"k"] = 1 WHERE pk = 'q' and REMOVE m[@"k"] get Invalid path component for simple path on the service and here (the base gave an empty text); a row would hold it.
What
The PartiQL lexer now reads
@as a token of its own. The parser reads it as DynamoDB does, as an operator that must have a name after it. Before, the lexer read@with a word directly after it as that word, so@size(a)was the callsize(a). It refused@before any other character with an empty text.eat_at_signincrates/core/src/partiql/parser.rsreads the@and refuses anything but a name after it withIdentifier must follow @-operator, the one new text. A name is an unquoted word ofWordClass::Nameor a quoted name, and white space may come between.path,parse_from_source,item_map,literal_value,in_list,in_bag,bracket_step,term_in_parenthesesand the two map key positions call it.unsigned_atomreads an operand that starts with@throughpath.(after the name does not start a call.spanandinner_spanstep past the@, so a refusal gives the position of the name.@with the texts they give any token that is not a name. They are the table ofUPDATE,DELETEandINSERT, aSETorREMOVEtarget, and the step after a dot.parser/terms/tests.rsholds the measured statements.tests/test_partiql_grammar.pygets six rows.The base of this PR is #1070, which rewrites the parser files that this change touches.
Fixes #1382
Why
DynamoDB was measured in us-east-1 on 23 November 2026 with ExecuteStatement on tables that do not exist. 102 statements went out twice each, with the same answer both times. Of the first 63, ExtendDB on main gave DynamoDB's answer for 20. Some of the answers, with "not well formed" for the prefix
Statement wasn't well formed, can't be processed::SELECT @a FROM t, and@ a,@"a",@a.bor@a[0]in place of@aResourceNotFoundExceptionSELECT @size(a) FROM t, and@select,@1,@@aor@(a)in place of@size(a)Identifier must follow @-operatorSELECT * FROM t WHERE pk = @,SELECT * FROM t WHERE a IN @Identifier must follow @-operatorSELECT @foo(a) FROM tExpected FROM after SELECT listSELECT * FROM t WHERE @foo(a) = 1Unexpected token after expressionUPDATE t SET @a = 1,UPDATE t REMOVE @a,UPDATE @"t" SET a = 1Expected identifier for simple pathUPDATE t SET m[@k] = 1,UPDATE t REMOVE m[@k]Invalid path component for simple pathINSERT INTO t VALUE {'pk': @a}Unsupported data type: a under key root, at theaINSERT INTO t VALUE {@1: 1}Identifier must follow @-operatorSELECT * FROM t WHERE @a IS INT4aA lexer error later in the statement still comes first, as on DynamoDB.
Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1152 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 870 passed.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.Expected a literal value, where DynamoDB names its type #1383, andAT @xafter a table is PartiQL FROM:ATorBYwith no name after it getsUnexpected token after expression, where DynamoDB answersExpected identifier for AT-alias#1384. PartiQL (#411): ExtendDB refuses SET a = a + 1 + 1, and other parser forms and syntax texts differ #887 records two of the texts, and a name in a bag differs with or without@.tests/test_partiql_grammar.pyagainst the same build: 1014 passed, 3 skipped.Production is +97 -37, and the tests are +209 -6. This PR adds no conflict over its base. #1112 and #1095 conflict with #1070 itself, in the same hunks.
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.