Skip to content

fix(partiql): check the operand count of a condition function in a WHERE - #1431

Open
LeeroyHannigan wants to merge 1 commit into
fix/887-call-textsfrom
fix/1407-condition-operand-counts
Open

LeeroyHannigan wants to merge 1 commit into
fix/887-call-textsfrom
fix/1407-condition-operand-counts

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

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.

  • The count check covers attribute_exists, attribute_not_exists and size, which take one operand, and attribute_type, begins_with and contains, which take two.
  • attribute_exists and attribute_not_exists with 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 of size or contains.
  • These refusals, the IN list limit, the operator limit and the path refusal of a literal before IS MISSING come in written order. They come after a syntax error and after what the walk of the condition meets. An example is a number that breaks an item number rule, or a +.
  • 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 after the parser reads the predicate.

The code:

  • crates/core/src/partiql/parser/condition.rs: check_operand_count and check_presence_operand, called from term_predicate and from Parser::call in operands.rs. not_expr counts the NOTs after the predicate.
  • crates/core/src/partiql/parser/walk.rs: refuse_before_count keeps the first refusal of the operands in the slot that resolve reports.
  • 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_refusal gives the path text, beside operand_count_refusal. check_presence_operands in forms.rs is gone.
  • The measured statements are rows of the existing table in 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 is SELECT * FROM <T> WHERE pk = 'q' AND <condition>. COUNT stands for the operand count refusal, PATH for the document path refusal, and RNFE for ResourceNotFoundException Requested resource not found, which means that the statement reached the table. "After 300" means that a = 1 AND comes 149 times before the condition.

<condition> DynamoDB ExtendDB at the base
contains(m) COUNT, contains, 1 contains requires two arguments
"Contains"(m) COUNT, contains, 1 RNFE
size(m, 1) = 1 COUNT, size, 2 RNFE
"Begins_With"(m) COUNT, begins_with, 1 RNFE
attribute_type(m) COUNT, attribute_type, 1 attribute_type requires two arguments
a = attribute_exists(1) PATH, attribute_exists RNFE
a IN [attribute_exists(1)] PATH, attribute_exists RNFE
contains(m, attribute_exists(1)) PATH, attribute_exists RNFE
attribute_exists(1) AND contains(m) PATH, attribute_exists PATH, attribute_exists
contains(m) AND attribute_exists(1) COUNT, contains, 1 contains requires two arguments
contains(m), after 300 COUNT, contains, 1 contains requires two arguments
NOT attribute_exists(1), after 300 PATH, attribute_exists PATH, attribute_exists

With 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 warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A control ran the new table rows of each change on the code before it. Each row whose answer the change moves failed there.
  • A SQLite release build of this branch, one change before its last, answered 142 of the 156 measured requests as DynamoDB does. These include the BatchExecuteStatement and ExecuteTransaction forms of six rows. The probe scripts of fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410 give 210 of 236, with no answer changed from the base. The nine PartiQL test files of tests/ pass against that build.
  • The last change counts a run of NOT after the predicate. The measurements for it cover five rows with a NOT after 300 operators, and the parser and the table test give each the DynamoDB answer.

Production is +211 -114 lines, and the tests are +152 -12.

The measured rows that still differ from DynamoDB:

This PR adds one conflict to its base: with #1112 in condition.rs, where #1112 wraps forms::check_presence_operands in term_predicate. Keep the lines of this PR and drop the wrap.

Closes #1407

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.

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

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

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

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.

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

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

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