Skip to content

Commit 44ab7c2

Browse files
Edward AlmondEdward Almond
authored andcommitted
Implement DynamoDB projection expression for GetItem
- Parse comma-separated attribute names from projection expression - Support ExpressionAttributeNames for aliasing (e.g., #n -> name) - Return only requested attributes instead of full item
1 parent da67d47 commit 44ab7c2

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

ruststack-dynamodb/src/storage.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ impl DynamoDBStorage {
582582
table_name: &str,
583583
key: Item,
584584
projection_expression: Option<&str>,
585-
_expression_attribute_names: Option<&HashMap<String, String>>,
585+
expression_attribute_names: Option<&HashMap<String, String>>,
586586
) -> Result<Option<Item>, DynamoDBError> {
587587
let table = self
588588
.tables
@@ -593,9 +593,25 @@ impl DynamoDBStorage {
593593
let item = table.items.get(&key_str).map(|r| r.clone());
594594

595595
// Apply projection if specified
596-
if let (Some(_item), Some(_proj)) = (&item, projection_expression) {
597-
// TODO: Implement projection expression
598-
// For now, return full item
596+
if let Some(proj) = projection_expression {
597+
if let Some(item) = item {
598+
let attributes: Vec<&str> = proj.split(',').map(|s| s.trim()).collect();
599+
600+
let mut projected = Item::new();
601+
for attr in attributes {
602+
let attr_name = if let Some(names) = expression_attribute_names {
603+
names.get(attr).map(|s| s.as_str()).unwrap_or(attr)
604+
} else {
605+
attr
606+
};
607+
608+
if let Some(value) = item.get(attr_name) {
609+
projected.insert(attr_name.to_string(), value.clone());
610+
}
611+
}
612+
613+
return Ok(Some(projected));
614+
}
599615
}
600616

601617
Ok(item)

0 commit comments

Comments
 (0)