in src/control.rs [672:708]
fn generate_essential_key_definitions(
given_keys: &[String],
) -> (Vec<KeySchemaElement>, Vec<AttributeDefinition>) {
let mut key_schema: Vec<KeySchemaElement> = vec![];
let mut attribute_definitions: Vec<AttributeDefinition> = vec![];
for (key_id, key_str) in given_keys.iter().enumerate() {
let key_and_type = key_str.split(',').collect::<Vec<&str>>();
if key_and_type.len() >= 3 {
error!(
"Invalid format for --keys option: '{}'. Valid format is '--keys myPk,S mySk,N'",
&key_str
);
std::process::exit(1);
}
// assumes first given key is Partition key, and second given key is Sort key (if any).
key_schema.push(KeySchemaElement {
attribute_name: String::from(key_and_type[0]),
key_type: if key_id == 0 {
String::from("HASH")
} else {
String::from("RANGE")
},
});
// If data type of key is omitted, dynein assumes it as String (S).
attribute_definitions.push(AttributeDefinition {
attribute_name: String::from(key_and_type[0]),
attribute_type: if key_and_type.len() == 2 {
key_and_type[1].to_uppercase()
} else {
String::from("S")
},
});
}
(key_schema, attribute_definitions)
}