Skip to content

fix(partiql): read a condition function as an operand in a WHERE - #1436

Open
LeeroyHannigan wants to merge 1 commit into
fix/1407-condition-operand-countsfrom
fix/1415-size-as-operand
Open

LeeroyHannigan wants to merge 1 commit into
fix/1407-condition-operand-countsfrom
fix/1415-size-as-operand

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

In a PartiQL WHERE condition, ExtendDB now reads an unquoted condition function as an operand, as it reads the quoted one. What may follow an operand may follow the call, and an argument may hold a LIKE. The result of a call also has a type, and the operator that takes the call checks it:

  • size gives a number. attribute_exists, attribute_not_exists, attribute_type, begins_with and contains give a boolean.
  • AND, OR and NOT refuse a number operand. BETWEEN, <, <=, > and >= refuse a boolean one. The refusal is the existing text Incorrect operand type for operator or function; operator or function: <op>, operand type: <type>.
  • A WHERE condition that is only a call to size gets the existing text WHERE clause must contain an expression that resolves to a boolean.
  • IN, = and <> take a call of either type.

The code:

  • crates/core/src/partiql/parser/condition.rs: term_predicate has no branch of its own for an unquoted condition function. Parser::call reads both spellings, so the operand count and path checks of fix(partiql): check the operand count of a condition function in a WHERE #1431 run there as before. A call with no comparison after it becomes its predicate through call_predicate.
  • crates/core/src/partiql/operand_types.rs: check_ordering_operands gives a call its type with call_type, and checks it against AND, OR, NOT, BETWEEN and the ordering operators. For the whole condition it uses NOT_A_CONDITION from parser.rs.
  • crates/core/src/partiql/parser.rs: NO_COMPARISON goes, because no code gives that text now.
  • 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 #1431.

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. Each statement is SELECT * FROM <T> WHERE pk = 'q' AND <condition>, unless the table shows the whole statement. TYPE stands for the operand type text, and RNFE for ResourceNotFoundException Requested resource not found, which means that the statement reached the table. NO COMPARISON and AFTER EXPRESSION stand for Statement wasn't well formed, can't be processed: with Expected a comparison operator or Unexpected token after expression after it.

<condition> DynamoDB ExtendDB at the base
size(m) BETWEEN 1 AND 2 RNFE NO COMPARISON
size(m) + 1 = 2 Unsupported operator in Condition Expression. Operator: + NO COMPARISON
size(m) IS NULL The left hand side argument to IS must be a Variable Reference, Literal, or Path NO COMPARISON
contains(m LIKE 'x', 'a') Unsupported operator in Condition Expression. Operator: like Statement wasn't well formed, can't be processed: Expected RIGHT_PAREN
size(m) TYPE, AND, N NO COMPARISON
"Size"(m) TYPE, AND, N RNFE
NOT size(m) TYPE, NOT, N NO COMPARISON
begins_with(m, 'a') BETWEEN 1 AND 2 TYPE, BETWEEN, BOOL AFTER EXPRESSION
"Begins_With"(m, 'a') BETWEEN 1 AND 2 TYPE, BETWEEN, BOOL RNFE
begins_with(m, 'a') < 1 TYPE, <, BOOL AFTER EXPRESSION
contains(m, 'a') IN [1] RNFE AFTER EXPRESSION
SELECT * FROM <T> WHERE size(m) WHERE clause must contain an expression that resolves to a boolean NO COMPARISON

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: 870 passed and 1 failed. The failed test is backup::tests::a_healthy_store_makes_create_backup_store_backed, which passed alone and in the run before. This PR changes no backup code. 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 the first two rounds on the code before each round. Each row whose answer the round moves failed there. The last change adds 25 rows with DynamoDB's answers, which this branch already gave. They were not run on the code before the change.
  • A SQLite release build of the change before the last gave DynamoDB's answer to all 49 rows of PartiQL WHERE: ExtendDB gives a syntax error after an unquoted size call, where DynamoDB reads the call as an operand #1415 and its bounding rows. The base gave DynamoDB's answer to 29 of them. The build also gave DynamoDB's answer to the 11 statements that the last round of the change moved. Of 27 other statements that the change moves, 21 got DynamoDB's answer. The other 380 measured requests of PartiQL WHERE: a condition function with the wrong number of operands gets other answers than DynamoDB, and a quoted name skips the check #1407 and fix(partiql): give calls and NOT the service's refusals in SET values and conditions #1410 gave the same answers as on the base, 333 of them DynamoDB's. The nine PartiQL test files of tests/ pass against that build. The last change adds the 25 table rows and a sentence to the module doc of operand_types.rs, and writes one match in condition.rs as a let chain. The release build did not run on it. The unit tests and lints above ran on it.

Over the base, production adds 132 lines and removes 95. The tests add 82 lines and remove 16.

The measured rows that still differ from DynamoDB:

On a table that exists, the quoted spelling of begins_with, contains and attribute_type now builds the predicate that the unquoted spelling builds. So pk = 'a' AND "Begins_With"(sk, 'b') reads the partition by its sort key, as the unquoted spelling does. The base read the whole table with the call as a filter. This is not measured on a table that exists.

This PR adds no conflict to its base. With #1112, the block in condition.rs is the branch that this PR removes. Keep the lines of this PR, and move the deferral of #1112's EXISTS refusal into check_presence_operand.

Closes #1415

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 in a WHERE condition reads as an operand, with its
name quoted or not. What may follow an operand may follow the call, and an
argument may hold a LIKE. A call to size gives a number, and the other
condition functions give a boolean. AND, OR and NOT refuse a number
operand. BETWEEN and the ordering operators refuse a boolean one. A WHERE
condition that is only a call to size gets the refusal of a condition that
is not a boolean.

Closes #1415

@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 condition function now reads as an operand in a WHERE at b3c1ce7, and every row this adds gives the service's answer on a missing table, but on a table that exists a boolean call compared with anything other than a bare true or false is still refused where the service runs it, and 100 nested contains or attribute_type calls are now refused where the base ran them. Of 390 ExecuteStatement shapes sent twice to us-east-1 and to this head and its base, this head gives the service's answer on 315 and the base on 112, and all 51 new rows match byte for byte. A quoted "Begins_With"(sk, 'b') now reads by key: with a 350 KB item in another partition it costs 0.5 read units here and on the service, against 43.0 on the base. Six of seven controls fail as they should, fmt, clippy, the core and engine lib tests (1151 and 871 passed) 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 clippy, the core and engine lib tests (1247 and 979) and the 1.94.0 check pass.

I will approve once a boolean call compared by =, <> or IN runs as the service runs it on a table that exists, with tests that run it there, and a call at the start of a predicate nests to the depth the base read.

self.refuse_bare_operand(left_start);
return Ok(WhereExpr::Function(BARE_OPERAND.to_owned(), vec![left]));
};
// A call whose result is BOOL compared with a boolean is the

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.

On the table edbv-1436-c-t, which exists, the service runs each of these after WHERE pk = 'q' AND, twice with the same items, and this head refuses each with ValidationException unexpected token at position N, a ConditionExpression text the service never gives: begins_with(m, 'a') = 1 (no items), <> 1 (6 items), = (true) (s1), = 'x', = null, contains(m, 'a') IN [1] (none), IN [true] (b1, s1, s2), begins_with(m, 'a') IN [true, 1] (s1), NOT IN [1] (6), begins_with(m, 'a') = begins_with(m, 'a') (6), attribute_exists(m) = attribute_exists(m) (6) and attribute_exists(m) = ? with {"BOOL": true} (b1, b2, e, s1, s2). On writes, DELETE ... AND begins_with(m, 'a') = 1 and UPDATE ... SET z = 1 WHERE ... AND contains(m, 'a') IN [1] get ConditionalCheckFailedException from the service and expected ')' here. The parser hands Compare(Operand::Function(..), ..) and In(Operand::Function(..), ..) to the engine, which renders begins_with(#n0, :v0) = :v1 (expr_bridge.rs:111, :134, write/expr_builder.rs:100), and the classic grammar has no comparison of a boolean function; only = true, = false, <> true and <> false work, through ComparedWithBoolean. The base refused these too, with Unexpected token after expression, but the module doc at operand_types.rs:15-26 and the body say IN, = and <> take a call of either type and list these as statements that run, and rows TV10, TL1, TL5 and S2 pass only because their table is missing. The service's answers fit a plain boolean: the call is true or false for every item (false where m is absent), = holds for the same boolean, <> is its negation, IN is the OR of = over the members, and a call against a call compares the two values.

/// function with another number of operands than it takes (see
/// [`Parser::check_operand_count`]) stands for its 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.

A call at the start of a predicate is now read through operand(), one Nest::Operand level deeper, against MAX_OPERAND_DEPTH 100 (limits.rs:65). contains( or attribute_type( nested 100 deep reaches the table on the service (ResourceNotFoundException, twice) and on the base, and gets Statement wasn't well formed, can't be processed: expression nesting depth exceeded here; 99 levels pass on all three. The body names the extra level only for size, which the service refuses anyway. Reading the call without the extra level, as the base did for the unquoted name, or a cap that covers it (#1428 raises it to 500), and a row at 100 levels, would hold it.

// may follow an operand, and a quoted presence function as a
// predicate gets the path check. In the brackets of an ORDER BY
// term or a SET target a condition function gets the brackets'
// A condition function, quoted or not, reads as any other call,

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.

These rows run check_statement on the missing table "ets-parityat-missing", so they hold only that every check passed; no new test runs a statement on a table that exists, which is how the comparisons above went unseen. Optional, smaller: with the "attribute_type" => WhereExpr::AttributeType arm at condition.rs:489 removed, the core and engine partiql tests pass, and predicates/tests.rs:319 drops the unquoted size(a LIKE 'x') = 1 assertion without a row, though this head answers it as the service does (Unsupported operator in Condition Expression. Operator: like). This file grows from 1053 to 1123 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