Skip to content

fix(partiql): give calls and NOT the service's refusals in SET values and conditions - #1410

Open
LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/887-call-texts
Open

LeeroyHannigan wants to merge 1 commit into
fix/1382-at-operatorfrom
fix/887-call-texts

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

PartiQL gives calls and NOT the refusals DynamoDB gives them in SET values, WHERE conditions, INSERT values and statements of their own.

  • An aggregate (avg, count, max, min, sum) with no argument is a syntax error: Aggregate functions are always unary. Only count takes *, and the call must close after it. Another aggregate with * gets <name>(*) is not allowed. DISTINCT and ALL need an operand.
  • Unquoted nullif, coalesce and cast have their own argument rules: nullif(m) is Expected COMMA, cast(m) is Expected AS.
  • A quoted name is the aggregate only in lower case: "count" is count, and "COUNT"(m) is Unrecognized function: count. Any other quoted name looks up 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 in a condition get The function is not allowed in a condition expression; function: <name>.
  • As a statement of its own, nullif, coalesce and cast get Unsupported operation: NullIf, Coalesce or Cast, as an aggregate gets CallAgg. This holds inside parentheses too. A sign before the call makes it a call like any other, with the EXISTS text.
  • The parser reads a call as an INSERT item value by the same rules before it refuses the call.
  • NOT in a SET value gets Unsupported operator in Update Expression. Operator: not, ahead of a refusal of its operand.

The code:

  • crates/core/src/partiql/values.rs: call_name gives the name the code compares a call by, from its written name and its quotes. Call::refusal names the refused function. The second copy of the condition function list, in forms.rs, is gone.
  • crates/core/src/partiql/parser/operands.rs: form_arguments reads the arguments of the aggregate, nullif, coalesce and cast forms.
  • crates/core/src/partiql/parser/terms.rs: the NOT branch of reserved_word_term and the statement forms in bare_term.
  • crates/core/src/partiql/parser/forms.rs, parser.rs and statements.rs: a call as an INSERT value.
  • The measured statements are one table of 140 rows in 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 prefix Statement wasn't well formed, can't be processed: , and RNFE for ResourceNotFoundException Requested resource not found.

Statement DynamoDB ExtendDB at the base
UPDATE <T> SET a = "count"() WHERE pk = 'q' not well formed: Aggregate functions are always unary Unsupported token in expression: count
UPDATE <T> SET a = count(*, 1) WHERE pk = 'q' not well formed: Expected RIGHT_PAREN not well formed: Unexpected term
UPDATE <T> SET a = count(ALL m) WHERE pk = 'q' Unsupported token in expression: count at 1:39:5 not well formed: Unexpected keyword
UPDATE <T> SET a = "COUNT"(m) WHERE pk = 'q' Unrecognized function: count at 1:39:7 Unsupported token in expression: count
UPDATE <T> SET ss = "SET_ADD"(ss, <<'b'>>) WHERE pk = 'q' RNFE Unrecognized function: set_add
avg(*) not well formed: avg(*) is not allowed not well formed: Unexpected term
nullif(1, 2) Unsupported operation: NullIf EXISTS can only be used in ExecuteTransaction write requests.
(-count(1)) EXISTS can only be used in ExecuteTransaction write requests. Unsupported operation: CallAgg
INSERT INTO <T> VALUE {'pk': 'q', 'a': cast(m AS INT)} Unsupported data type: cast under key root at 1:59:4 not well formed: Expected RIGHT_PAREN
UPDATE <T> SET x = NOT -0.0 WHERE pk = 'q' Unsupported operator in Update Expression. Operator: not not well formed: Unexpected operator

Part 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 warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A SQLite release build of the commit answered 234 of 266 measured requests as DynamoDB does. Quoted names such as "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.py and tests/test_partiql_unsupported_forms.py against 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:

In ExecuteTransaction, DynamoDB answers a sign before an aggregate or a form statement, such as -count(1), with a 500 InternalFailure. This PR answers Unsupported 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_call reads 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 with form_arguments.

Production code is +267 -118 lines, and the tests are +232 -6.

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.

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

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

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.

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

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.

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

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.

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!(

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.

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

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

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