Repository navigation
fix(partiql): give calls and NOT the service's refusals in SET values and conditions - #1410
LeeroyHannigan wants to merge 1 commit into
Conversation
… and conditions DynamoDB refuses a call in a SET value or a WHERE condition by its name once the statement parses. An aggregate with no argument is a syntax error. Only count takes *, and the call must close after it. DISTINCT and ALL need an operand. The unquoted nullif, coalesce and cast forms have argument rules of their own. A quoted aggregate name is the aggregate only in lower case. Any other quoted name is the function of that name in lower case, so "SIZE" is size. Quoted nullif, coalesce and cast are calls like any other. if_not_exists and list_append are refused in a condition by name. NOT in a SET value is refused as an unsupported update operator, ahead of what its operand holds. call_name in values.rs gives the name the code compares a call by, from its written name and its quotes. The parser, the SET value walk and the set_add and set_delete check use it. The parser reads the aggregate, nullif, coalesce and cast forms, also in an INSERT value, where a NOT is not refused. A nullif, coalesce or cast statement is an unsupported NullIf, Coalesce or Cast operation, also in parentheses. Such a statement or an aggregate statement with a sign before it, also inside parentheses, is a call like any other. The second copy of the condition function list in forms.rs is gone. Measured 2026-11-23 in us-east-1 on a table that does not exist. Part of #887
demohan
left a comment
There was a problem hiding this comment.
Calls and NOT in SET values and conditions get the service's refusals at 4b18700 in the forms the table covers, and quoted function names run as they do on the service. The ten rows of the body's table reproduce on us-east-1 and the base, and all 140 rows of the engine table give the service's answer on the wire in the operation each names. Of 292 statements sent twice as ExecuteStatement, BatchExecuteStatement and ExecuteTransaction, this head matches the service on 778 of 876 answers, no statement is accepted on one side and refused on the other, and on tables that exist, quoted "If_Not_Exists", "Set_Delete", "SET_ADD", "LIST_APPEND", "SIZE", "Contains", "BEGINS_WITH" and the others store and select the same items as the service in 15 of 15 statements (the base refused "Set_Delete" and "SET_ADD"). NOT in a SET value matches in every form measured. Eight of eight controls fail as they should, fmt, clippy and the 1.91.1 check are clean, the body's test counts reproduce, CI is green on 59 of 59, and it merges onto main at d4dd0ba without conflict, where the core and engine lib tests (1248 and 979), clippy and the 1.94.0 check pass.
Nearby forms of the calls this writes still differ, and one answer the base gave right is now wrong (below). I will approve once these give the service's text, with rows in the table.
| let args = self.arguments(argument)?; | ||
| let args = self.form_arguments(&call.name, argument)?; | ||
| // The walk meets a call's arguments before its name (measured | ||
| // 2026-11-02: `foo(1e126)` is refused for the number, `foo(1 + 1)` |
There was a problem hiding this comment.
For an aggregate, nullif, coalesce or cast, the service refuses the call ahead of what its arguments hold; here the arguments win. After WHERE ... AND (column 57): count(1e126) = 1, count(1 + 1) = 1, count(?) = 1 with no parameters, count(upper(m)) = 1, count(m LIKE 'a') = 1 and "count"(1e126) = 1 all get Unsupported token in expression: count at 1:57:5 (:7 quoted) on the service, and here a number overflow, Operator: +, the parameter count, Unrecognized function: upper at 1:63:5 or Operator: like; nullif(m, 1e126) = 1 gets Unsupported token in expression: UNKNOWN at 1:57:6, coalesce(1e126) = 1 ... UNKNOWN at 1:65:1 and cast(1e126 AS INT) = 1 ... cast at 1:57:4, each a number overflow here. In a SET value (values.rs:553-572) count(1e126), count(<<>>), count(upper(m)), nullif(1e126, 1), coalesce(1e126) and cast(1e126 AS INT) answer the same way. A syntax error inside the arguments still wins on the service (count(*, 1), nullif(m)), so the order is syntax, then the form's refusal, then the arguments. The base answers all but the two cast rows the same, but this is the text and place this change writes, and the comment at lines 335-337 would need to cover these forms.
| )); | ||
| } | ||
| let mut args = Vec::new(); | ||
| if aggregate && self.eat(&TokenKind::Star) { |
There was a problem hiding this comment.
* gets other texts on the service. "count"(*) gets Statement wasn't well formed, can't be processed: only COUNT can be used with a wildcard in a SET value, a condition, a statement and an INSERT value, and here Unsupported token in expression: count at 1:39:7, Unsupported operation: CallAgg or Expected a literal value; "COUNT"(*), "Count"(*), "Avg"(*) and "MAX"(*) get <name as written>(*) is not allowed there and Unexpected term here ("avg"(*), "sum"(*) and unquoted AVG(*) match). After DISTINCT or ALL, count(ALL *) gets COUNT(ALL *) is not supported, count(DISTINCT *) COUNT(DISTINCT *) is not supported and avg(DISTINCT *) avg(*) is not allowed, and Unexpected term here; the body lists only count(DISTINCT *). So a quoted aggregate name in any case keeps the * rule (values.rs:368), and * after DISTINCT or ALL is read and refused.
| "cast" => unsupported(name, at), | ||
| _ => format!( | ||
| "Unrecognized function: {} at {at}", | ||
| name.trim_matches('"').to_ascii_lowercase() |
There was a problem hiding this comment.
name.trim_matches('"') also strips quote characters that are part of the name, which the base kept: WHERE ... AND """upper"""(m) = 1 gets Unrecognized function: "upper" at 1:57:11 on the service and the base, and Unrecognized function: upper at 1:57:11 here; SET a = """upper"""(m), """COUNT"""(m) (service "count") and """nullif"""(m) lose the quotes too. "a""b"(m) = 1 matches. Carrying whether the name was quoted as its own field on Call and Operand::Function, rather than as quote characters in the name, would keep them.
| if let Err(e) = self.form_arguments(&name, Self::operand) { | ||
| return Some(e); | ||
| } | ||
| Some(ParseError::new(format!( |
There was a problem hiding this comment.
As an INSERT item value, nullif(m, 1) gets Unsupported data type: UNKNOWN under key root at 1:59:6 and coalesce(m, 1) ... UNKNOWN under key root at 1:67:1 (the () on the service, and nullif and coalesce under key root at 1:59:8 here, though a SET value names them UNKNOWN. A quoted name called as an INSERT value is Expected a literal value here, since at_call (lines 121-127) takes only an unquoted name, where the service reads it as a call: "count"() gets Aggregate functions are always unary, "count"(*) only COUNT can be used with a wildcard, "upper"(m) Unsupported data type: upper under key root at 1:59:7, "COUNT"(m) count under key root, "size"(m) size under key root at 1:59:6 and """upper"""(m) "upper" under key root at 1:59:11. The body says an INSERT value reads a call by the same rules.
| ("Q1", es, update("a = \"nullif\"(m, 1)"), unrecognized("nullif", "1:39:8")), | ||
| ("Q2", es, update("a = \"coalesce\"(m, 1)"), unrecognized("coalesce", "1:39:10")), | ||
| ("F3", es, update("a = cast(m AS INT)"), token("cast", "1:39:4")), | ||
| ("C6", es, update("a = CAST(m AS VARCHAR(5))"), token("cast", "1:39:4")), |
There was a problem hiding this comment.
Optional. The labels C6 (lines 757 and 874) and C7 (763 and 875) are each used twice, once for a SET value and once for an INSERT value, so a failure cannot be told apart by its label. This file grows from 676 to 901 lines with the table.
What
PartiQL gives calls and NOT the refusals DynamoDB gives them in SET values, WHERE conditions, INSERT values and statements of their own.
avg,count,max,min,sum) with no argument is a syntax error:Aggregate functions are always unary. Onlycounttakes*, and the call must close after it. Another aggregate with*gets<name>(*) is not allowed.DISTINCTandALLneed an operand.nullif,coalesceandcasthave their own argument rules:nullif(m)isExpected COMMA,cast(m)isExpected AS."count"iscount, and"COUNT"(m)isUnrecognized function: count. Any other quoted name looks up the function of that name in lower case, so"SIZE"issize. Quotednullif,coalesceandcastare calls like any other.if_not_existsandlist_appendin a condition getThe function is not allowed in a condition expression; function: <name>.nullif,coalesceandcastgetUnsupported operation: NullIf,CoalesceorCast, as an aggregate getsCallAgg. This holds inside parentheses too. A sign before the call makes it a call like any other, with the EXISTS text.Unsupported operator in Update Expression. Operator: not, ahead of a refusal of its operand.The code:
crates/core/src/partiql/values.rs:call_namegives the name the code compares a call by, from its written name and its quotes.Call::refusalnames the refused function. The second copy of the condition function list, informs.rs, is gone.crates/core/src/partiql/parser/operands.rs:form_argumentsreads the arguments of the aggregate,nullif,coalesceandcastforms.crates/core/src/partiql/parser/terms.rs: the NOT branch ofreserved_word_termand the statement forms inbare_term.crates/core/src/partiql/parser/forms.rs,parser.rsandstatements.rs: a call as an INSERT value.crates/engine/src/partiql/mod.rs,calls_and_not_in_set_values_and_conditions_get_the_services_refusals.The base of this PR is #1386, which makes
@a token of its own.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, or with no table. Each request went out twice, with the same answer both times. The positions count that table name. "Not well formed" stands for the prefixStatement wasn't well formed, can't be processed:, and RNFE forResourceNotFoundExceptionRequested resource not found.UPDATE <T> SET a = "count"() WHERE pk = 'q'Aggregate functions are always unaryUnsupported token in expression: countUPDATE <T> SET a = count(*, 1) WHERE pk = 'q'Expected RIGHT_PARENUnexpected termUPDATE <T> SET a = count(ALL m) WHERE pk = 'q'Unsupported token in expression: count at 1:39:5Unexpected keywordUPDATE <T> SET a = "COUNT"(m) WHERE pk = 'q'Unrecognized function: count at 1:39:7Unsupported token in expression: countUPDATE <T> SET ss = "SET_ADD"(ss, <<'b'>>) WHERE pk = 'q'Unrecognized function: set_addavg(*)avg(*) is not allowedUnexpected termnullif(1, 2)Unsupported operation: NullIfEXISTS can only be used in ExecuteTransaction write requests.(-count(1))EXISTS can only be used in ExecuteTransaction write requests.Unsupported operation: CallAggINSERT INTO <T> VALUE {'pk': 'q', 'a': cast(m AS INT)}Unsupported data type: cast under key root at 1:59:4Expected RIGHT_PARENUPDATE <T> SET x = NOT -0.0 WHERE pk = 'q'Unsupported operator in Update Expression. Operator: notUnexpected operatorPart of #887
Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1152 passed, 1 ignored.cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed. Clippy for both crates with--all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean."SIZE","If_Not_Exists"and"Set_Delete"store and test an item as the unquoted names do.tests/test_partiql_grammar.py,tests/test_partiql_write.pyandtests/test_partiql_unsupported_forms.pyagainst that build: 1014 passed and 3 skipped, 301 passed, 36 passed.These measured forms still differ from DynamoDB, on the base and on this PR:
NOT a = 1,NOT a AND b), CASE after NOT, NOT in a WHERE operand and NOT in bracketscount(DISTINCT *)set_add, and of a SET call, a number or an empty bag ahead of a NOT (PartiQL (#411): for a statement with two faults, the first refusal differs from DynamoDB, and so does the number set text #886)Unsupported clause: LIMIT, where DynamoDB answersUnexpected token after expression#1400, which fix(partiql): refuse a LIMIT as an unsupported clause only after a SELECT #1406 fixes), and 100 or more NOTs (PartiQL (#411): the parser's nesting caps refuse statements that DynamoDB runs #885)In ExecuteTransaction, DynamoDB answers a sign before an aggregate or a form statement, such as
-count(1), with a 500InternalFailure. This PR answersUnsupported operation in transaction., the text DynamoDB gives"COUNT"(1)there.Not measured: a called name with escaped quotes in it, such as
"""upper"""(m), now loses those quote characters in the refusal text.With #1398,
refused_callreads a call inside a list or map literal, and it does not apply the form rules of this PR. Whichever of the two merges second should read that call withform_arguments.Production code is +267 -118 lines, and the tests are +232 -6.
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.