Repository navigation
fix(partiql): refuse a LIMIT as an unsupported clause only after a SELECT - #1406
LeeroyHannigan wants to merge 1 commit into
Conversation
…LECT Measured on DynamoDB on 23 November 2026: a LIMIT after a SELECT is "Unsupported clause: LIMIT" at the token after it. A SELECT with nothing after its LIMIT gets "Unexpected term". After an UPDATE, a DELETE, an INSERT or an EXISTS statement, the LIMIT is a token left over: "Unexpected token after expression". Parser::finish gave the unsupported clause refusal after every statement. It now gives it after a SELECT only, gives "Unexpected term" when the statement ends at the LIMIT, and answers the other statements with the trailing token error. On main a bag of BOOL or a number map key in an UPDATE value is refused while the statement parses, so those two rows of #1400 keep their value refusals. At the head of #1398, where those refusals wait for the parse, they get the syntax error. Refs #1400
demohan
left a comment
There was a problem hiding this comment.
A LIMIT is refused as an unsupported clause only after a SELECT at 1731ff6, and nothing main answers as the service does changes. Of 365 shapes sent twice to us-east-1 and to this head and main on SQLite and PostgreSQL, in ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, 151 move from main's answer to the service's and the two backends agree everywhere. Five controls fail as they should, fmt, clippy, the 1.91.1 check and the core and engine tests are clean, and CI is green on 64 of 64. It merges onto main at 222d80a without conflict, passes the 1.94.0 check and the tests there, and answers all 365 shapes as this head; merged with #1112 as well, it also answers them all alike, so the two do not conflict in order. No merged PR fixes #1400.
I will approve once a SELECT's LIMIT followed by any token that cannot start a term gets the service's term error, and BatchExecuteStatement and ExecuteTransaction have rows in the tests.
| if s.eq_ignore_ascii_case("LIMIT") && matches!(stmt, Statement::Select(_)) => | ||
| { | ||
| self.bump(); | ||
| if matches!(self.peek().kind, TokenKind::Eof) { |
There was a problem hiding this comment.
This gives the term error only when the LIMIT is the last token; the service gives it for any token that cannot start a term. In all three operations, ... LIMIT; and ... LIMIT ; get Unexpected term from the service and Unsupported clause: LIMIT at 1:57:1 here, though the body names that case as "nothing after it"; LIMIT = gets Unexpected operator, LIMIT ) Unexpected term, and LIMIT LIMIT and SELECT ... LIMIT WHERE ... Unexpected keyword from the service. Main answers these as this head does. Calling term_error for the end, a semicolon, a closing token, an operator or a keyword, or reading the value with operand() and then requiring the end as insert_without_value does, would match. The comment's "after any other statement it is a token left over" does not hold for a DELETE without WHERE: DELETE FROM T LIMIT 1 and its variants get Where clause does not contain a mandatory equality... here and on main (the missing WHERE is refused at statements.rs:421 before this runs), where the service gives Unexpected token after expression.
| ); | ||
| // After any other statement a LIMIT is a token left over. | ||
| let leftover = wf("Unexpected token after expression"); | ||
| for sql in [ |
There was a problem hiding this comment.
These rows call only parse_for_execute_statement. BatchExecuteStatement and ExecuteTransaction go through parse_for_request, and restoring main's answer for those two alone (matches!(stmt, Statement::Select(_)) || !self.refuse_exists) passes all 1146 core and 871 engine tests. Rows for those two operations, EXISTS(...) LIMIT 1 above all, would hold them.
What
PartiQL refuses a LIMIT as an unsupported clause only after a SELECT, as DynamoDB does.
Unsupported clause: LIMIT, at the token after it. With nothing after it, the LIMIT now getsStatement wasn't well formed, can't be processed: Unexpected term.Statement wasn't well formed, can't be processed: Unexpected token after expression. It is a syntax error, so it comes ahead of the refusals that wait for the statement to parse.The code:
crates/core/src/partiql/parser.rs: the LIMIT arm ofParser::finishruns for a SELECT only, and answers a LIMIT at the end of the statement withterm_error. Any other statement reaches thetrailing_errorarm.parser/tests/statements.rs,a_limit_is_an_unsupported_clause_only_after_a_select.Why
DynamoDB was measured in us-east-1 on 23 November 2026 with ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, on the table
"ets-parityat-missing", which does not exist. Each request went out twice, with the same answer both times. #1400 and its comment give the tables. "Not well formed" stands for the prefixStatement wasn't well formed, can't be processed:.SELECT * FROM <T> WHERE pk = 'q' LIMIT 1Unsupported clause: LIMIT at 1:59:1SELECT * FROM <T> WHERE pk = 'q' LIMITUnexpected termUnsupported clause: LIMIT at 1:53:1UPDATE <T> SET a = 1 WHERE pk = 'q' LIMIT 1Unexpected token after expressionUnsupported clause: LIMIT at 1:62:1DELETE FROM <T> WHERE pk = 'q' LIMIT 1Unexpected token after expressionUnsupported clause: LIMIT at 1:57:1INSERT INTO <T> VALUE {'pk': 'q'} LIMIT 1Unexpected token after expressionUnsupported clause: LIMIT at 1:60:1EXISTS(SELECT * FROM <T> WHERE pk = 'q') LIMIT 1Unexpected token after expressionEXISTS can only be used in ExecuteTransaction write requests.In BatchExecuteStatement and ExecuteTransaction the UPDATE, DELETE and INSERT rows get the same syntax error. In ExecuteTransaction it comes after
Validation failed in TransactStatements[0]:.Two rows of #1400 put a refused value before the LIMIT:
SET a = <<true>>andSET a = {1: 1}. On main the parser refuses those values while it reads them, sofinishdoes not run and the value refusal stays. With this change on the head of #1398, where those refusals wait for the parse, both rows get the syntax error in the three operations. #1400 can close once this PR and #1398 have both merged.Refs #1400
Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1146 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.parser.rs, the new test fails.tests/test_partiql_check_order.py,tests/test_partiql_grammar.pyandtests/test_partiql_phase3.pyagainst that build: 1077 passed, 3 skipped.cargo test -p extenddb-core --libgave 1154 passed and 1 ignored.Production code is +18 -12 lines, and the tests are +25 -1.
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.