Skip to content

Commit

Permalink
test: add integration test for bwrite
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Oda <[email protected]>
  • Loading branch information
tmyoda committed Apr 7, 2024
1 parent 9f1a578 commit 5b17141
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 137 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
services:
dynamodb:
# Pinned to the version not to be broken with latest
image: amazon/dynamodb-local:1.22.0
image: amazon/dynamodb-local:2.2.1
ports:
- 8000:8000
- 8001:8000
Expand Down
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,48 @@ No item found.
`dy bwrite` internally calls [BatchWriteItem API](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html) and is used for putting and deleting multiple items.
You can specify the `--input` option when providing operations from a JSON file that follows the Request Syntax of BatchWriteItem API.
```bash
$ dy bwrite --input request.json
$ cat request.json
{
"__TABLE_NAME__": [
{
"PutRequest": {
"Item": {
"pk": { "S": "ichi" },
"ISBN": { "S": "111-1111111111" },
"Price": { "N": "2" },
"Dimensions": { "SS": ["Giraffe", "Hippo" ,"Zebra"] },
"PageCount": { "NS": ["42.2", "-19", "7.5", "3.14"] },
"InPublication": { "BOOL": false },
"Binary": {"B": "dGhpcyB0ZXh0IGlzIGJhc2U2NC1lbmNvZGVk"},
"BinarySet": {"BS": ["U3Vubnk=", "UmFpbnk=", "U25vd3k="]},
"Nothing": { "NULL": true },
"Authors": {
"L": [
{ "S": "Author1" },
{ "S": "Author2" },
{ "N": "42" }
]
},
"Details": {
"M": {
"Name": { "S": "Joe" },
"Age": { "N": "35" },
"Misc": {
"M": {
"hope": { "BOOL": true },
"dream": { "L": [ { "N": "35" }, { "NULL": true } ] }
}
}
}
}
}
}
}
]
}
```
You can also use `--put` or `--del` options to achieve corresponding operations.
Expand All @@ -1011,7 +1051,7 @@ pk attributes
2 {"this_is_set":["x","y","z"]}
```
The --put, --del, and --input options can be used simultaneously.
The `--put`, `--del`, and `--input` options can be used simultaneously.
```bash
$ dy bwrite --del '{"pk": "1"}' --del '{"pk": "2"}' --put '{"pk": "3", "this_is_set": <<"a","b","c">>}'
Expand All @@ -1021,7 +1061,7 @@ pk attributes
```
```bash
$ dy bwrite --del '{"pk": "1"}' --del '{"pk": "2"}' --put '{"pk": "3", "this_is_set": <<"a","b","c">>}' --input request.json
$ dy bwrite --del '{"pk": "1"}' --del '{"pk": "2"}' --put '{"pk": "3", "this_is_set": <<"a","b","c">>}' --input request.json
```
## Working with Indexes
Expand Down
6 changes: 3 additions & 3 deletions src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ pub async fn batch_write_item(
if let Some(items) = puts {
for item in items.iter() {
let attrs = parser.parse_dynein_format(None, item)?;
validate_item_has_keys(&attrs, &ts)?;
validate_item_keys(&attrs, &ts)?;
write_requests.push(WriteRequest {
put_request: Some(PutRequest { item: attrs }),
delete_request: None,
Expand All @@ -288,7 +288,7 @@ pub async fn batch_write_item(
if let Some(keys) = dels {
for key in keys.iter() {
let attrs = parser.parse_dynein_format(None, key)?;
validate_item_has_keys(&attrs, &ts)?;
validate_item_keys(&attrs, &ts)?;
write_requests.push(WriteRequest {
put_request: None,
delete_request: Some(DeleteRequest { key: attrs }),
Expand Down Expand Up @@ -572,7 +572,7 @@ fn json_binary_val_to_bytes(v: &JsonValue) -> Bytes {
}

// Check if the item has a partition key and sort key.
fn validate_item_has_keys(
fn validate_item_keys(
attrs: &HashMap<String, AttributeValue>,
ts: &app::TableSchema,
) -> Result<(), DyneinBatchError> {
Expand Down
Loading

0 comments on commit 5b17141

Please sign in to comment.