in src/data.rs [1397:1445]
fn generate_scan_expressions(
ts: &app::TableSchema,
attributes: &Option<String>,
keys_only: bool,
) -> GeneratedScanParams {
// Early return for the default condition. no --keys-only, no --attributes.
if !keys_only && attributes.is_none() {
return GeneratedScanParams {
exp: None,
names: None,
};
}
// dynein always shows primary key(s) i.e. pk and sk (if any).
let mut names = HashMap::<String, String>::new();
names.insert(String::from("#DYNEIN_PKNAME"), ts.clone().pk.name);
let mut returning_attributes: Vec<String> = vec![String::from("#DYNEIN_PKNAME")];
if let Some(sk) = &ts.sk {
returning_attributes.push(String::from("#DYNEIN_SKNAME"));
names.insert(String::from("#DYNEIN_SKNAME"), sk.clone().name);
};
// if keys_only flag is true, no more attribute would be added.
if keys_only {
} else if let Some(_attributes) = attributes {
let mut i: usize = 0;
let attrs: Vec<&str> = _attributes.split(',').map(|x| x.trim()).collect();
for attr in attrs {
// skip if attributes contain primary key(s) as they're already included in the expression.
if attr == ts.pk.name || (ts.sk.is_some() && attr == ts.clone().sk.unwrap().name) {
continue;
}
let placeholder = String::from("#DYNEIN_ATTRNAME") + &i.to_string();
returning_attributes.push(placeholder.clone());
names.insert(placeholder, String::from(attr));
i += 1;
}
};
let expression: String = returning_attributes.join(",");
debug!("generated ProjectionExpression: {}", &expression);
debug!("generated ExpressionAttributeNames: {:?}", &names);
GeneratedScanParams {
exp: Some(expression),
names: Some(names),
}
}