Skip to content

fix(partiql): refuse AT or BY with no name after a FROM table - #1389

Open
LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/1384-from-alias-names
Open

LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/1384-from-alias-names

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

After a PartiQL FROM table, AT and BY now need a name after them. A quoted name counts. Any other token, and the end of the statement, gets Statement wasn't well formed, can't be processed: Expected identifier for AT-alias, or the same text with BY-alias. Before, ExtendDB took AT or BY as an alias only before an unquoted name. Any other AT or BY stayed in the statement, and the parser answered it as a token after the end.

  • source_aliases in crates/core/src/partiql/parser.rs checks the token after AT or BY with the existing name_follows. It refuses anything that is not a name with the keyword's text, in upper case.
  • The test at_and_by_after_a_table_are_aliases in parser/tests/statements.rs becomes one table of the measured statements, at_and_by_after_a_table_take_a_name.

The base of this PR is #1386, which makes @ a token of its own.

Fixes #1384

Why

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, with the same answer both times. Each statement is SELECT * FROM "<missing>" <rest>, and "not well formed" stands for the prefix Statement wasn't well formed, can't be processed: .

<rest> DynamoDB
AT x WHERE pk = 'q', BY x WHERE pk = 'q', AT "x" WHERE pk = 'q' Aliasing is not supported
AT 1 WHERE pk = 'q', at 1 WHERE pk = 'q', AT @x WHERE pk = 'q', AT WHERE pk = 'q', AT, x AT 1 WHERE pk = 'q' not well formed: Expected identifier for AT-alias
BY 1 WHERE pk = 'q', BY @x WHERE pk = 'q', by @x WHERE pk = 'q', BY not well formed: Expected identifier for BY-alias
AS @x WHERE pk = 'q', AS 1 WHERE pk = 'q' not well formed: Expected identifier for AS-alias

ExtendDB on main gave 3 of the first 12 of these statements DynamoDB's answer.

Testing done

  • cargo test -p extenddb-core --lib --no-fail-fast: 1152 passed, 1 ignored.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A SQLite release build of the first commit of this PR answered the first 12 statements as DynamoDB does. The last three rows of the table, at 1, by @x and BY at the end, came later and pass in the unit table.
  • tests/test_partiql_grammar.py against the same build: 1014 passed, 3 skipped.
  • With the production code of the base, 8 of the test's first 11 rows failed.

Production is +14 -8, and the test is +23 -5. Only the SELECT FROM source calls source_aliases, so UPDATE, DELETE and INSERT answer as before. This PR adds no conflict over its base.

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.

After a PartiQL FROM table, Amazon DynamoDB requires a name after AT and
after BY. A quoted name is a name there. Anything else gets "Statement
wasn't well formed, can't be processed: Expected identifier for
AT-alias", or the same text with BY-alias. The end of the statement gets
it too, and a lower-case at or by gets the same upper-case text.
DynamoDB was measured in us-east-1 on 23 November 2026 on a
table that does not exist, each statement twice.

source_aliases read AT or BY as an alias only before an unquoted name. It
left any other AT or BY in place, and the parser then answered it as a
token after the statement. It now checks the token after AT or BY with
name_follows and refuses anything that is not a name with the keyword's
text.

Fixes #1384

@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 FROM table followed by AT or BY with no name now gets the service's refusal at 0a04304. Of 165 ExecuteStatement shapes sent twice to us-east-1 and to this head, base and main, this head matches the service byte for byte on 160, and on 15 of 15 BatchExecuteStatement and ExecuteTransaction shapes; every one of the 113 answers that changed from base moved to the service's, and the 5 that differ are UPDATE, DELETE and EXISTS shapes that base and main answer the same way. An AT or BY at the end of the statement, after a new line or comment, before a bad WHERE, LIMIT or ORDER BY, in an IN subquery and after a FROM path all match, and the AT or BY syntax error wins over the deferred refusals, as on the service. Four of five controls fail as they should, the core lib tests (1152 passed), fmt, clippy and the 1.91.1 check 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 (1248 passed) and the 1.94.0 check pass.

In the body, 9 of the committed table's first 11 rows fail on base (8 was the first commit's 11), main gives the service's answer on 2 of the body table's first 12 (3 of the issue's 12), and tests/test_partiql_grammar.py gives 1014 passed, 3 skipped on base too and has no AT or BY row, so it shows only that nothing regressed.

for sql in [
"SELECT * FROM \"t\" AT x WHERE pk = 'p'",
"SELECT * FROM \"t\" BY x WHERE pk = 'p'",
fn at_and_by_after_a_table_take_a_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.

Optional. Nothing here holds AT being read before BY: with ["BY", "AT"] at parser.rs:523 the 38 statement tests pass. Three rows the service answers would hold it: AT x BY y gets Aliasing is not supported, AT x BY 1 gets Statement wasn't well formed, can't be processed: Expected identifier for BY-alias, and BY x AT y gets Statement wasn't well formed, can't be processed: Unexpected token after expression; with them, the swapped order fails at AT x BY y.

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