Repository navigation
fix(partiql): check the operand count of a condition function in a WHERE - #1431
LeeroyHannigan wants to merge 1 commit into
Conversation
A condition function with the wrong number of operands gets the service's operand count refusal, quoted or not and in any case. The count check and the document path check of attribute_exists and attribute_not_exists apply wherever the call stands in the condition. These checks apply in written order together with the IN list limit, the operator limit and the document path check of IS MISSING. They come after a syntax error and after what the walk of the condition meets. Each check of a call or of IS MISSING comes before the call or the IS counts as an operator. A run of NOT before a predicate counts once the predicate is read. Closes #1407
demohan
left a comment
There was a problem hiding this comment.
The operand count of a condition function in a WHERE is now checked in most places it stands at 41044ad, but a presence function or IS MISSING with a bad operand followed by a comparison, IN or BETWEEN now gets a syntax error, where main, the base and the service give the count or path refusal. Of 321 requests sent twice to us-east-1 and to this head, its base and main, 203 of the first 221 match the service here, 130 of them moved from a wrong base answer, and all 12 rows of the body's table match; 29 requests that main and the base answered as the service does are now wrong (below). Eight of nine controls fail as they should, fmt, clippy, the 1.91.1 check and the core and engine lib tests (1151 and 871 passed) are clean, the PartiQL pytest files pass against this head (3170 passed), 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 (1247 and 979) and the 1.94.0 check pass.
I will approve once a condition function or IS test with a bad operand keeps its refusal when a comparison, IN, BETWEEN, LIKE or an arithmetic operator follows it, with rows for those, and a test holds the order of the operator count and the check in call.
| /// number of operands than it takes (see [`Parser::check_operand_count`]) | ||
| /// the predicate stands for the call and never runs. | ||
| #[inline(never)] | ||
| fn term_predicate(&mut self) -> PResult<WhereExpr> { |
There was a problem hiding this comment.
The refusal of attribute_exists and attribute_not_exists (count or path) and of a literal before IS MISSING (predicates.rs:147-166) is now deferred, and the parse goes on; an unquoted condition function used as a predicate, and an IS test, take nothing that may follow an operand, so the parse fails and the syntax error wins. After SELECT * FROM "edbv-1431-c-missing" WHERE pk = 'q' AND, attribute_exists(1) = 1, < 1, <> 1, = 'x', = a, IN [1] and BETWEEN 1 AND 2, attribute_not_exists(1) = 1, NOT attribute_exists(1) = 1, ATTRIBUTE_EXISTS(1) = 1, 1 IS MISSING = 1, 1 IS MISSING = true and 'x' IS NOT MISSING = 1 get Operator or function requires a document path; operator or function: attribute_exists (or attribute_not_exists) on the service, on main 3534c9e and on the base, and attribute_exists(m, 1) = 1 and attribute_exists() = 1 get Incorrect number of operands for operator or function; operator or function: attribute_exists, number of operands: 2 (0); here each gets Statement wasn't well formed, can't be processed: Unexpected token after expression, in ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, and in DELETE and UPDATE conditions. The quoted "Attribute_Exists"(1) = 1 goes through Parser::call and is right. The same path gives the syntax error where the base gave contains requires two arguments and the service the count refusal, for contains(m) = 1, contains(m) IN [1], contains(m) BETWEEN 1 AND 2, (contains(m)) = 1, begins_with(m) = 1 and attribute_type(m, 'S', 1) = 1, and where the service gives Unsupported operator in Condition Expression. Operator: + for contains(m) + 1 = 2 or Operator: like for contains(m) LIKE 'x'. Reading an unquoted condition function as the quoted one is read when an operand tail follows it, and the same after an IS test whose refusal is deferred, would keep the refusal. The body's "wherever the call stands in the condition" does not yet hold for these, nor for size(m, 1) alone, with BETWEEN or with IN (Expected a comparison operator here and on the base, size, number of operands: 2 on the service).
| /// [`Parser::check_operand_count`]); in a SET value the checks made then | ||
| /// refuse it (see `values`). | ||
| fn call(&mut self, name: String) -> PResult<Operand> { | ||
| let within = self.within_operator_limit(); |
There was a problem hiding this comment.
No test holds within_operator_limit() before count_operator(): with the two lines swapped, the core partiql tests (267) and the engine table pass. After 300 operators, "Contains"(m) gets Incorrect number of operands for operator or function; operator or function: contains, number of operands: 1 on the service and here, and a row for it ("a = 1 AND ".repeat(149) then "Contains"(m)) fails under the swap with The expression contains too many operators; operator count: 301.
| // comparison, as a BETWEEN bound, as an IN member), after a | ||
| // syntax error and after what the walk of the condition meets | ||
| // (measured 2026-11-23 and 2026-11-24). | ||
| ("Y6", es, select("contains(m)"), count("contains", 1)), |
There was a problem hiding this comment.
Optional. Labels repeat among the added rows (P1 to P7, C5) and against rows already in the table (O1, O3 to O11, N1, B11), so a label alone no longer names one row. The file grows from 901 to 1053 lines.
What
In a PartiQL WHERE condition, a condition function with the wrong number of operands now gets DynamoDB's operand count refusal,
Incorrect number of operands for operator or function; operator or function: <name>, number of operands: <n>. This holds for the name quoted in any case, and wherever the call stands in the condition.attribute_exists,attribute_not_existsandsize, which take one operand, andattribute_type,begins_withandcontains, which take two.attribute_existsandattribute_not_existswith a literal or a parameter as their operand get the document path refusal,Operator or function requires a document path; operator or function: <name>. The path check runs in the same place as the count check, so it covers each position of a call. These are the start of a predicate, the right of a comparison, an IN member, a BETWEEN bound and an argument ofsizeorcontains.+.The code:
crates/core/src/partiql/parser/condition.rs:check_operand_countandcheck_presence_operand, called fromterm_predicateand fromParser::callinoperands.rs.not_exprcounts the NOTs after the predicate.crates/core/src/partiql/parser/walk.rs:refuse_before_countkeeps the first refusal of the operands in the slot thatresolvereports.crates/core/src/partiql/parser/predicates.rs: the refusal of a literal before IS MISSING goes into the same slot.crates/core/src/partiql/values.rs:path_operand_refusalgives the path text, besideoperand_count_refusal.check_presence_operandsinforms.rsis gone.crates/engine/src/partiql/mod.rs.No error text is new. The base of this PR is #1410.
Why
DynamoDB was measured in us-east-1 on 23 and 24 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. #1407 and its comment give the rows of the issue. Each statement isSELECT * FROM <T> WHERE pk = 'q' AND <condition>. COUNT stands for the operand count refusal, PATH for the document path refusal, and RNFE forResourceNotFoundExceptionRequested resource not found, which means that the statement reached the table. "After 300" means thata = 1 ANDcomes 149 times before the condition.<condition>contains(m)contains, 1contains requires two arguments"Contains"(m)contains, 1size(m, 1) = 1size, 2"Begins_With"(m)begins_with, 1attribute_type(m)attribute_type, 1attribute_type requires two argumentsa = attribute_exists(1)attribute_existsa IN [attribute_exists(1)]attribute_existscontains(m, attribute_exists(1))attribute_existsattribute_exists(1) AND contains(m)attribute_existsattribute_existscontains(m) AND attribute_exists(1)contains, 1contains requires two argumentscontains(m), after 300contains, 1contains requires two argumentsNOT attribute_exists(1), after 300attribute_existsattribute_existsWith this PR each row gets the DynamoDB answer.
Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1151 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.tests/pass against that build.Production is +211 -114 lines, and the tests are +152 -12.
The measured rows that still differ from DynamoDB:
sizecall that DynamoDB reads as an operand, such assize(m) BETWEEN 1 AND 2, and the operand type text forsize(m)alone. PartiQL WHERE: ExtendDB gives a syntax error after an unquoted size call, where DynamoDB reads the call as an operand #1415 covers these 8 rows.m[attribute_exists(1)] = 1. PartiQL (#411): ExtendDB refuses SET a = a + 1 + 1, and other parser forms and syntax texts differ #887 lists these forms.EXISTS(SELECT ...)around a path refusal in BatchExecuteStatement, where DynamoDB gives the EXISTS text. fix(core): refuse EXISTS outside a transaction ahead of other faults #1112 gives EXISTS that refusal.This PR adds one conflict to its base: with #1112 in
condition.rs, where #1112 wrapsforms::check_presence_operandsinterm_predicate. Keep the lines of this PR and drop the wrap.Closes #1407
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.