Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bwrite command does not support binary data types #168

Closed
tmyoda opened this issue Sep 13, 2023 · 1 comment
Closed

bwrite command does not support binary data types #168

tmyoda opened this issue Sep 13, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@tmyoda
Copy link
Contributor

tmyoda commented Sep 13, 2023

Using binary types with 'bwrite' command results in the following error.

dy bwrite --table test  --input tests/resources/test_batch_write.json                                                                                                                                       
[2023-09-13T09:07:17Z ERROR dy::batch] [skip] invalid/unsupported DynamoDB JSON format: Object {"B": String("dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk")}
[2023-09-13T09:07:17Z ERROR dy::batch] [skip] invalid/unsupported DynamoDB JSON format: Object {"BS": Array [String("dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"), String("sdfsdhSRHwFEDw4f")]}

This issue seems to be due to the lack of implementation for B and BS types in the following.

dynein/src/batch.rs

Lines 413 to 475 in f95b9fc

fn ddbjson_val_to_attrval(ddb_jsonval: &JsonValue) -> Option<AttributeValue> {
// prepare shared logic that can be used for both SS and NS.
let set_logic = |val: &JsonValue| -> Vec<String> {
val.as_array()
.expect("should be valid JSON array")
.iter()
.map(|el| el.as_str().expect("should -> str").to_string())
.collect::<Vec<String>>()
};
// following list of if-else statements would be return value of this function.
if let Some(x) = ddb_jsonval.get("S") {
Some(AttributeValue {
s: Some(x.as_str().unwrap().to_string()),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("N") {
Some(AttributeValue {
n: Some(x.as_str().unwrap().to_string()),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("BOOL") {
Some(AttributeValue {
bool: Some(x.as_bool().unwrap()),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("SS") {
Some(AttributeValue {
ss: Some(set_logic(x)),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("NS") {
Some(AttributeValue {
ns: Some(set_logic(x)),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("L") {
let list_element = x
.as_array()
.unwrap()
.iter()
.map(|el| ddbjson_val_to_attrval(el).expect("failed to digest a list element"))
.collect::<Vec<AttributeValue>>();
debug!("List Element: {:?}", list_element);
Some(AttributeValue {
l: Some(list_element),
..Default::default()
})
} else if let Some(x) = ddb_jsonval.get("M") {
let inner_map: HashMap<String, AttributeValue> = ddbjson_attributes_to_attrvals(x);
Some(AttributeValue {
m: Some(inner_map),
..Default::default()
})
} else if ddb_jsonval.get("NULL").is_some() {
Some(AttributeValue {
null: Some(true),
..Default::default()
})
} else {
None
}
}

I will work on this issue.

@tmyoda
Copy link
Contributor Author

tmyoda commented Oct 30, 2023

#170 resolved this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants