Repository navigation
fix(partiql): read a condition function as an operand in a WHERE - #1436
LeeroyHannigan wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
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:
sizegives a number.attribute_exists,attribute_not_exists,attribute_type,begins_withandcontainsgive a boolean.<,<=,>and>=refuse a boolean one. The refusal is the existing textIncorrect operand type for operator or function; operator or function: <op>, operand type: <type>.sizegets the existing textWHERE clause must contain an expression that resolves to a boolean.=and<>take a call of either type.The code:
crates/core/src/partiql/parser/condition.rs:term_predicatehas no branch of its own for an unquoted condition function.Parser::callreads 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 throughcall_predicate.crates/core/src/partiql/operand_types.rs:check_ordering_operandsgives a call its type withcall_type, and checks it against AND, OR, NOT, BETWEEN and the ordering operators. For the whole condition it usesNOT_A_CONDITIONfromparser.rs.crates/core/src/partiql/parser.rs:NO_COMPARISONgoes, because no code gives that text now.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 isSELECT * FROM <T> WHERE pk = 'q' AND <condition>, unless the table shows the whole statement. TYPE stands for the operand type text, and RNFE forResourceNotFoundExceptionRequested resource not found, which means that the statement reached the table. NO COMPARISON and AFTER EXPRESSION stand forStatement wasn't well formed, can't be processed:withExpected a comparison operatororUnexpected token after expressionafter it.<condition>size(m) BETWEEN 1 AND 2size(m) + 1 = 2Unsupported operator in Condition Expression. Operator: +size(m) IS NULLThe left hand side argument to IS must be a Variable Reference, Literal, or Pathcontains(m LIKE 'x', 'a')Unsupported operator in Condition Expression. Operator: likeStatement wasn't well formed, can't be processed: Expected RIGHT_PARENsize(m)"Size"(m)NOT size(m)begins_with(m, 'a') BETWEEN 1 AND 2"Begins_With"(m, 'a') BETWEEN 1 AND 2begins_with(m, 'a') < 1<, BOOLcontains(m, 'a') IN [1]SELECT * FROM <T> WHERE size(m)WHERE clause must contain an expression that resolves to a booleanWith 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 isbackup::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 warningsandcargo +1.97.0 fmt --all -- --checkare clean.tests/pass against that build. The last change adds the 25 table rows and a sentence to the module doc ofoperand_types.rs, and writes onematchincondition.rsas 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:
sizeorbegins_with, such assize(size(m)) = 1. DynamoDB refuses it for its type (PartiQL WHERE: a call as the operand of size or begins_with is not checked for its type, where DynamoDB refuses it #1434).sizegetexpression nesting depth exceeded, because a call at the start of a predicate now nests one operand level deeper. 99 levels still parse. fix(partiql): raise the nesting caps to the depths the service reads #1428 raises the operand cap to 500.On a table that exists, the quoted spelling of
begins_with,containsandattribute_typenow builds the predicate that the unquoted spelling builds. Sopk = '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.rsis the branch that this PR removes. Keep the lines of this PR, and move the deferral of #1112's EXISTS refusal intocheck_presence_operand.Closes #1415
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.