Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
af51f01
fix(query): refuse a key condition with no HASH equality the way the …
LeeroyHannigan Oct 31, 2026
125e1de
Merge origin/fix/key-condition-one-per-key into fix/427-lone-non-equa…
LeeroyHannigan Nov 25, 2026
0c4ddaf
Merge origin/main into fix/427-lone-non-equality
LeeroyHannigan Nov 25, 2026
43b39c7
test(core): keep the shape rows that the parser still refuses
LeeroyHannigan Nov 25, 2026
30a8424
fix(query): refuse a key condition with no HASH equality ahead of the…
LeeroyHannigan Nov 25, 2026
aeec7b0
refactor(core): drop the copies of the reference and duplicate checks
LeeroyHannigan Nov 25, 2026
5e08d02
refactor(core): read the clause attributes through attr_of alone
LeeroyHannigan Nov 25, 2026
060e499
fix(core): refuse a key schema with no HASH attribute with an interna…
LeeroyHannigan Nov 25, 2026
a08ea1e
refactor(core): share the three key schema sentences of a Query
LeeroyHannigan Nov 25, 2026
5144771
test(core): one table per sentence in the no HASH equality tests
LeeroyHannigan Nov 25, 2026
19a7162
fix(server): keep a key condition with no equality out of dynamodb:At…
LeeroyHannigan Nov 25, 2026
5698b3c
test(wire): label the measured rows without the issue number
LeeroyHannigan Nov 25, 2026
ad103a6
test(wire): compare the ALL_PROJECTED_ATTRIBUTES refusal by equality
LeeroyHannigan Nov 25, 2026
21a392d
Merge fix/key-condition-one-per-key into fix/427-lone-non-equality
LeeroyHannigan Nov 25, 2026
2c2b8c4
refactor(query): call the engine refusal only when the HASH equality …
LeeroyHannigan Nov 25, 2026
056c368
docs(query): shorten the doc of the engine refusal to its two steps
LeeroyHannigan Nov 25, 2026
9cd0127
test(wire): add row A3, a missed key schema element ahead of the Sele…
LeeroyHannigan Nov 25, 2026
ee8a156
test(wire): refuse a Query on a vector index ahead of the HASH equali…
LeeroyHannigan Nov 25, 2026
a13cc4b
test(wire): name the key schema the vector refusal rows were measured on
LeeroyHannigan Nov 25, 2026
b60edf4
Merge fix/key-condition-one-per-key into fix/427-lone-non-equality
LeeroyHannigan Nov 25, 2026
2475b85
refactor(query): drop the copy of the HASH definition in the engine r…
LeeroyHannigan Nov 25, 2026
fbce34a
test(wire): state the order of the value checks that the rows measure
LeeroyHannigan Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions crates/core/src/error/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ pub fn validation_errors_detected(clauses: &[String]) -> String {
/// authorization; the `GetShardIterator` handler checks the presence.
pub const INVALID_STREAM_ARN: &str = "Invalid StreamArn";

/// The service's answer to a `Query` key condition it cannot serve, such as
/// `pk > :x` on a key schema whose only HASH attribute is `pk`.
pub const QUERY_KEY_CONDITION_NOT_SUPPORTED: &str = "Query key condition not supported";

/// The service's answer to a `Query` key condition with no condition on
/// `attribute`, a key attribute the query needs.
#[must_use]
pub fn missed_key_schema_element(attribute: &str) -> String {
format!("Query condition missed key schema element: {attribute}")
}

/// The service's answer to a `Query` key condition on a key schema with
/// several key attributes when the HASH attributes in `attributes` have no
/// equality condition.
#[must_use]
pub fn hash_attributes_without_equality(attributes: &[&str]) -> String {
format!(
"HASH key attributes {} must have equality conditions specified in the query",
attributes.join(", ")
)
}

/// Keys for error message templates. Compile-time checked — no stringly-typed lookups.
#[derive(Debug, Clone, Copy)]
pub enum ErrorMessageKey {
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
mod messages;

pub use messages::{
ErrorMessageKey, INVALID_STREAM_ARN, error_message, validation_error, validation_errors,
validation_errors_detected,
ErrorMessageKey, INVALID_STREAM_ARN, QUERY_KEY_CONDITION_NOT_SUPPORTED, error_message,
hash_attributes_without_equality, missed_key_schema_element, validation_error,
validation_errors, validation_errors_detected,
};

use crate::types::{CancellationReason, Item};
Expand Down
60 changes: 29 additions & 31 deletions crates/core/src/expression/key_condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ use crate::types::{
KeySchemaElement, KeyType, hash_key_elements, is_multipart_key_schema, range_key_elements,
};

mod no_hash_equality;

/// Parsed key condition: partition key value expression(s) and optional sort key condition.
///
/// For standard (single-attribute) keys, `pk_path`/`pk_value` hold the single PK condition
Expand All @@ -31,7 +33,10 @@ use crate::types::{
/// `extra_pk_conditions` holds additional PK equality conditions.
#[derive(Debug, Clone)]
pub struct KeyCondition {
/// First partition key attribute path (resolved name).
/// First partition key attribute path (resolved name). Empty when the
/// expression held one or two clauses and none is an equality; they are
/// then `sk_condition` and `extra_sk_conditions`, and
/// [`KeyCondition::refuse_without_hash_equality`] refuses them.
pub pk_path: Vec<PathElement>,
/// First partition key value expression (placeholder or literal).
pub pk_value: Expr,
Expand Down Expand Up @@ -635,9 +640,10 @@ pub fn has_duplicate_key_condition(
/// # Errors
///
/// As [`parse_key_condition`], plus `ValidationException` for each of the
/// faults above. A fault in the key condition's shape, such as no equality
/// on the partition key, is the `Err` inside `Ok`: the engine answers it
/// after the table checks, where the service does.
/// faults above. A fault in the key condition's shape, such as two
/// non-equality clauses beside an equality, is the `Err` inside `Ok`, for the
/// engine to answer after the table checks. A key condition with no equality
/// clause parses, and the engine refuses it once it knows the key schema.
pub fn parse_key_condition_with_maps(
tokens: &[Token],
maps: &ExpressionMaps,
Expand Down Expand Up @@ -828,17 +834,17 @@ fn classify_single(clause: RawClause) -> Result<KeyCondition, DynamoDbError> {
sk_condition: None,
extra_sk_conditions: Vec::new(),
}),
_ => Err(validation_err(
"Invalid KeyConditionExpression: partition key condition must use equality (=)",
)),
// The wording of the refusal depends on the key schema, which is not
// known here. See `KeyCondition::refuse_without_hash_equality`.
other => Ok(KeyCondition::without_equality(raw_to_sk(other), None)),
}
}

fn classify_pair(a: RawClause, b: RawClause) -> Result<KeyCondition, DynamoDbError> {
// When both clauses are Eq, we assign the first as PK and second as SK.
// The caller must call `resolve_pk_sk()` after parsing to correct the
// assignment using the table's key schema (REQ-QUERY-002).
// One must be EQ (the PK), the other is the SK condition
// One is EQ (the PK) and the other is the SK condition
match (a, b) {
(RawClause::Eq(pk_path, pk_value), sk) | (sk, RawClause::Eq(pk_path, pk_value)) => {
Ok(KeyCondition {
Expand All @@ -849,8 +855,11 @@ fn classify_pair(a: RawClause, b: RawClause) -> Result<KeyCondition, DynamoDbErr
extra_sk_conditions: Vec::new(),
})
}
_ => Err(validation_err(
"Invalid KeyConditionExpression: one condition must be an equality on the partition key",
// Neither clause is an equality. As for a single clause, the key
// schema decides the wording. See `KeyCondition::refuse_without_hash_equality`.
(a, b) => Ok(KeyCondition::without_equality(
raw_to_sk(a),
Some(raw_to_sk(b)),
)),
}
}
Expand Down Expand Up @@ -2377,27 +2386,16 @@ mod tests {
/// table checks.
#[test]
fn the_shape_is_refused_after_the_checks() {
for (expr, want) in [
("pk > :a", "partition key condition must use equality (=)"),
(
"pk > :a AND sk > :b",
"one condition must be an equality on the partition key",
),
(
"pk = :a AND sk > :b AND zz < :c",
"at most one non-equality condition is allowed",
),
] {
let tokens = tokenize(expr).unwrap();
let maps = ExpressionMaps::new(HashMap::new(), values_of(expr));
let shape = parse_key_condition_with_maps(&tokens, &maps)
.unwrap_or_else(|err| panic!("expr {expr} should pass the checks: {err:?}"));
assert_refused(
shape,
&format!("Invalid KeyConditionExpression: {want}"),
expr,
);
}
let expr = "pk = :a AND sk > :b AND zz < :c";
let tokens = tokenize(expr).unwrap();
let maps = ExpressionMaps::new(HashMap::new(), values_of(expr));
let shape = parse_key_condition_with_maps(&tokens, &maps)
.unwrap_or_else(|err| panic!("expr {expr} should pass the checks: {err:?}"));
assert_refused(
shape,
"Invalid KeyConditionExpression: at most one non-equality condition is allowed",
expr,
);
}

#[test]
Expand Down
Loading
Loading