Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4a2d382
fix(query): reject a KeyConditionExpression with two conditions on on…
LeeroyHannigan Oct 31, 2026
fa79d24
Merge main into fix/key-condition-one-per-key
LeeroyHannigan Nov 11, 2026
cc8d192
fix(auth): keep the LeadingKeys binding for a duplicate key condition
LeeroyHannigan Nov 11, 2026
8b49672
fix(core): check key condition references in the order they are written
LeeroyHannigan Nov 11, 2026
822c472
fix(query): refuse a duplicate key condition where the service does
LeeroyHannigan Nov 11, 2026
ef09b47
test(query): compare the exact undefined name message
LeeroyHannigan Nov 11, 2026
f910fa5
test(query): pin the measured reference and operator order on the wire
LeeroyHannigan Nov 11, 2026
968d084
refactor(core): mark the classifier's duplicate check as the map-less…
LeeroyHannigan Nov 11, 2026
a6c9fdf
test(engine): keep two rows in the key condition parse test
LeeroyHannigan Nov 11, 2026
1f722e0
style: apply rustfmt to the key condition and LeadingKeys changes
LeeroyHannigan Nov 11, 2026
c8bbdd0
fix(query): check the request's parameters ahead of a duplicate key c…
LeeroyHannigan Nov 11, 2026
9f5c743
fix(core): keep the parser's refusal for other <> and contains shapes
LeeroyHannigan Nov 11, 2026
a056da2
test(query): pin the measured operator and operand order on the wire
LeeroyHannigan Nov 11, 2026
5ea180d
fix(query): check parameters, then the filter, then the key condition
LeeroyHannigan Nov 11, 2026
b13ec53
fix(query): check Limit ahead of every other Query check
LeeroyHannigan Nov 11, 2026
c560e41
test(query): add the non-key and hash-only duplicate cases
LeeroyHannigan Nov 11, 2026
52a90f6
refactor(query): shorten comments and skip repeated filter checks
LeeroyHannigan Nov 11, 2026
9733e94
test(query): rewrite the one-per-key tests as tables of rows
LeeroyHannigan Nov 11, 2026
0634902
Merge origin/main into fix/key-condition-one-per-key
LeeroyHannigan Nov 16, 2026
e863639
refactor(query): read and check a Query body in one function
LeeroyHannigan Nov 19, 2026
e3e1da1
fix(server): refuse a duplicate key condition before the IAM decision
LeeroyHannigan Nov 19, 2026
3746280
refactor(query): reuse the server's names map for the duplicate check
LeeroyHannigan Nov 19, 2026
1c6a6c6
Merge origin/main into fix/key-condition-one-per-key
LeeroyHannigan Nov 23, 2026
534fb77
refactor(core): drop the classifier's one-condition-per-key check
LeeroyHannigan Nov 23, 2026
5d4ae9b
refactor(core): keep unsupported key condition clauses out of RawClause
LeeroyHannigan Nov 23, 2026
19bb1dd
fix(engine): read the key condition's shape after the table checks
LeeroyHannigan Nov 23, 2026
76e33b2
refactor(core): check the begins_with operand type in one place
LeeroyHannigan Nov 23, 2026
06d7d20
refactor(engine): run the second filter operand check for QueryFilter…
LeeroyHannigan Nov 23, 2026
a3d77ee
docs(server): say what the map-less key condition parse accepts
LeeroyHannigan Nov 23, 2026
b83c3b8
test(wire): drop the unreadable rows of the partition equality test
LeeroyHannigan Nov 23, 2026
98d09b3
docs(upgrade): list the Query requests that this change refuses
LeeroyHannigan Nov 23, 2026
8b43195
Merge origin/main into fix/key-condition-one-per-key
LeeroyHannigan Nov 25, 2026
bf57850
Merge origin/main into fix/key-condition-one-per-key
LeeroyHannigan Nov 25, 2026
468b256
fix(query): refuse an invalid Select before the IAM decision
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
734 changes: 633 additions & 101 deletions crates/core/src/expression/key_condition.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions crates/core/src/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ mod update_parser;
pub use ast::{ArithOp, CompareOp, Expr, PathElement, UpdateAction, removes_only};
pub use evaluator::evaluate_condition;
pub use key_condition::{
KeyClauseOperand, KeyCondition, SortKeyCondition, key_condition_clause_operands,
parse_key_condition,
KeyClauseOperand, KeyCondition, SortKeyCondition, has_duplicate_key_condition,
key_condition_clause_operands, parse_key_condition, parse_key_condition_with_maps,
};
pub use kind::ExpressionKind;
pub use parser::{parse_condition, parse_condition_with_depth_limit};
Expand Down
33 changes: 21 additions & 12 deletions crates/core/src/expression/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,18 +507,8 @@ pub fn validate_begins_with_operands(
maps: &ExpressionMaps,
) -> Result<(), DynamoDbError> {
match expr {
Expr::Function { name, args } if name == "begins_with" => {
if args.len() == 2
&& let Expr::Placeholder(ref placeholder) = args[1]
&& let Some(val) = maps.values.get(placeholder)
&& !matches!(val, AttributeValue::S(_) | AttributeValue::B(_))
{
let type_code = attribute_type_code(val);
return Err(DynamoDbError::ValidationException(format!(
"Incorrect operand type for operator or function; operator or function: begins_with, operand type: {type_code}"
)));
}
Ok(())
Expr::Function { name, args } if name == "begins_with" && args.len() == 2 => {
check_begins_with_operand(&args[1], maps, "")
}
Expr::And(left, right) | Expr::Or(left, right) => {
validate_begins_with_operands(left, maps)?;
Expand All @@ -529,6 +519,25 @@ pub fn validate_begins_with_operands(
}
}

/// Refuse a `begins_with` operand that is a `:value` other than a string or a
/// binary value, with `prefix` ahead of the message.
pub(crate) fn check_begins_with_operand(
operand: &Expr,
maps: &ExpressionMaps,
prefix: &str,
) -> Result<(), DynamoDbError> {
if let Expr::Placeholder(placeholder) = operand
&& let Some(val) = maps.values.get(placeholder)
&& !matches!(val, AttributeValue::S(_) | AttributeValue::B(_))
{
let type_code = attribute_type_code(val);
return Err(DynamoDbError::ValidationException(format!(
"{prefix}Incorrect operand type for operator or function; operator or function: begins_with, operand type: {type_code}"
)));
}
Ok(())
}

/// Return the DynamoDB type code for an AttributeValue (S, N, B, BOOL, NULL,
/// L, M, SS, NS, BS). Used in operand-type validation messages.
pub(crate) fn attribute_type_code(val: &AttributeValue) -> &'static str {
Expand Down
52 changes: 47 additions & 5 deletions crates/engine/src/expression_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::collections::HashMap;
use extenddb_core::error::DynamoDbError;
use extenddb_core::expression::{
Expr, ExpressionKind, ExpressionMaps, KeyCondition, PathElement, Token, UpdateAction,
parse_condition_with_depth_limit, parse_key_condition, parse_projection, parse_update_from,
tokenize_for, tokenize_with_limit, validate_no_reserved_words, validate_ordering_operand_types,
parse_condition_with_depth_limit, parse_key_condition_with_maps, parse_projection,
parse_update_from, tokenize_for, tokenize_with_limit, validate_no_reserved_words,
validate_ordering_operand_types,
};
use extenddb_core::limits::LimitsConfig;
use extenddb_core::types::{AttributeValue, ConditionalOperator, ExpectedAttributeValue};
Expand Down Expand Up @@ -237,16 +238,24 @@ pub fn parse_projection_expr(

/// Size-check, tokenize, reserved-word check, and parse a `KeyConditionExpression`.
///
/// `maps` holds the request's `ExpressionAttributeNames` and
/// `ExpressionAttributeValues`. The parse reads them to refuse an undefined
/// reference, a `begins_with` operand of the wrong type and a second
/// condition on one key attribute.
///
/// Errors carry the `KeyConditionExpression` prefix, matching Amazon `DynamoDB`.
///
/// # Errors
///
/// Returns `DynamoDbError::ValidationException` for over-size, syntax, or
/// reserved-word errors.
/// reserved-word errors, and for the faults above. A fault in the key
/// condition's shape is the `Err` inside `Ok`, as
/// [`parse_key_condition_with_maps`] returns it.
pub fn parse_key_condition_expr(
expr: &str,
maps: &ExpressionMaps,
limits: &LimitsConfig,
) -> Result<KeyCondition, DynamoDbError> {
) -> Result<Result<KeyCondition, DynamoDbError>, DynamoDbError> {
check_expression_size(expr, ExpressionKind::KeyCondition, limits)?;
tokenize_for(
expr,
Expand All @@ -257,7 +266,7 @@ pub fn parse_key_condition_expr(
if limits.enforce_reserved_keywords {
validate_no_reserved_words(&tokens)?;
}
parse_key_condition(&tokens)
parse_key_condition_with_maps(&tokens, maps)
})
.map_err(|e| prefix_expression_error(e, ExpressionKind::KeyCondition))
}
Expand Down Expand Up @@ -408,6 +417,39 @@ mod tests {
);
}

/// `parse_key_condition_expr` reads the request's `ExpressionAttributeNames`
/// and `ExpressionAttributeValues`, keyed with `#` and `:` as a request
/// carries them: a duplicate written through `#p` and an undefined `#u`
/// each answer the service's message. The core tests cover the other
/// rows.
#[test]
fn key_condition_parse_reads_the_request_maps() {
let names: HashMap<String, String> = [("#p".to_owned(), "pk".to_owned())].into();
let values: HashMap<String, AttributeValue> = [":a", ":b", ":c"]
.into_iter()
.map(|k| (k.to_owned(), AttributeValue::S("v".to_owned())))
.collect();
let maps = build_expression_maps(Some(&names), Some(&values));
for (expr, want) in [
(
"#p = :a AND pk = :b",
"Invalid KeyConditionExpression: KeyConditionExpressions must only contain \
one condition per key",
),
(
"pk = :a AND pk = :b AND #u = :c",
"Invalid KeyConditionExpression: An expression attribute name used in the \
document path is not defined; attribute name: #u",
),
] {
let got = parse_key_condition_expr(expr, &maps, &LimitsConfig::default());
assert!(
matches!(&got, Err(DynamoDbError::ValidationException(msg)) if msg == want),
"expr {expr}: got {got:?}"
);
}
}

/// Size and token limits raised so only the depth limit refuses the
/// expressions below.
fn raised() -> LimitsConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub use import_export::{handle_export_table, handle_import_table};
pub use item_authorizer::{ItemAccess, ItemAuthorization, ItemAuthorizer};
pub use list_tables::handle_list_tables;
pub use put_item::handle_put_item;
pub use query::handle_query;
pub use query::{handle_query, refuse_duplicate_key_condition};
pub use request_limits::check_request_item_counts;
pub use scan::handle_scan;
pub use search_vectors::handle_search_vectors;
Expand Down
Loading
Loading