-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add BatchPutItems method to WriteAPI #31
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
Merged
lakshmaji-till
merged 7 commits into
oolio-group:main
from
Santosh1608:chore/batch-write-items-expose
Dec 4, 2025
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
234189e
feat: Add BatchPutItems method to WriteAPI and implement item marshaling
Santosh1608 06c53c9
chore: remove BatchWriteItems and use BatchPutItems
Santosh1608 2f93ca0
chore: remove unused attributevalue import from batch_write_items.go
Santosh1608 ff64f5d
chore: add missing attributevalue import in batch_write_items.go
Santosh1608 d50ad60
fix: move table initialization outside of loop in BatchPutItems method
Santosh1608 a207f62
test: add unit tests for BatchPutItems method with various scenarios
Santosh1608 af75030
chore: dummy signed commit
Santosh1608 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,208 @@ | ||
| package tests | ||
|
|
||
| import ( | ||
| "context" | ||
| "reflect" | ||
| "testing" | ||
|
|
||
| "github.com/oolio-group/dynago" | ||
| ) | ||
|
|
||
| type BatchTestRecord struct { | ||
| ID string | ||
| Name string | ||
| Age int | ||
| } | ||
|
|
||
| func TestBatchPutItems(t *testing.T) { | ||
| table := prepareTable(t) | ||
| ctx := context.TODO() | ||
|
|
||
| testCases := []struct { | ||
| title string | ||
| inputs []dynago.BatchPutItemsInput | ||
| expected []BatchTestRecord | ||
| }{ | ||
| { | ||
| title: "single item batch", | ||
| inputs: []dynago.BatchPutItemsInput{ | ||
| { | ||
| PartitionKeyValue: dynago.StringValue("user_1"), | ||
| SortKeyValue: dynago.StringValue("profile_1"), | ||
| Item: BatchTestRecord{ | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: []BatchTestRecord{ | ||
| { | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| title: "multiple items batch", | ||
| inputs: []dynago.BatchPutItemsInput{ | ||
| { | ||
| PartitionKeyValue: dynago.StringValue("user_1"), | ||
| SortKeyValue: dynago.StringValue("profile_1"), | ||
| Item: BatchTestRecord{ | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| }, | ||
| { | ||
| PartitionKeyValue: dynago.StringValue("user_2"), | ||
| SortKeyValue: dynago.StringValue("profile_2"), | ||
| Item: BatchTestRecord{ | ||
| ID: "2", | ||
| Name: "Jane Smith", | ||
| Age: 25, | ||
| }, | ||
| }, | ||
| { | ||
| PartitionKeyValue: dynago.StringValue("user_3"), | ||
| SortKeyValue: dynago.StringValue("profile_3"), | ||
| Item: BatchTestRecord{ | ||
| ID: "3", | ||
| Name: "Bob Johnson", | ||
| Age: 35, | ||
| }, | ||
| }, | ||
| }, | ||
| expected: []BatchTestRecord{ | ||
| { | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| { | ||
| ID: "2", | ||
| Name: "Jane Smith", | ||
| Age: 25, | ||
| }, | ||
| { | ||
| ID: "3", | ||
| Name: "Bob Johnson", | ||
| Age: 35, | ||
| }, | ||
| }, | ||
| }, | ||
| { | ||
| title: "batch with more than 25 items (chunking test)", | ||
| inputs: func() []dynago.BatchPutItemsInput { | ||
| var inputs []dynago.BatchPutItemsInput | ||
| for i := 1; i <= 30; i++ { | ||
| inputs = append(inputs, dynago.BatchPutItemsInput{ | ||
| PartitionKeyValue: dynago.StringValue("batch_test"), | ||
| SortKeyValue: dynago.StringValue("item_" + string(rune(i+'0'))), | ||
| Item: BatchTestRecord{ | ||
| ID: string(rune(i + '0')), | ||
| Name: "User " + string(rune(i+'0')), | ||
| Age: 20 + i, | ||
| }, | ||
| }) | ||
| } | ||
| return inputs | ||
| }(), | ||
| expected: func() []BatchTestRecord { | ||
| var expected []BatchTestRecord | ||
| for i := 1; i <= 30; i++ { | ||
| expected = append(expected, BatchTestRecord{ | ||
| ID: string(rune(i + '0')), | ||
| Name: "User " + string(rune(i+'0')), | ||
| Age: 20 + i, | ||
| }) | ||
| } | ||
| return expected | ||
| }(), | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.title, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := table.BatchPutItems(ctx, tc.inputs) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %s", err) | ||
| } | ||
|
|
||
| // Verify all items were written correctly | ||
| for i, input := range tc.inputs { | ||
| var result BatchTestRecord | ||
| err, found := table.GetItem(ctx, input.PartitionKeyValue, input.SortKeyValue, &result) | ||
| if err != nil { | ||
| t.Fatalf("unexpected error retrieving item %d: %s", i, err) | ||
| } | ||
| if !found { | ||
| t.Fatalf("item %d not found", i) | ||
| } | ||
| if !reflect.DeepEqual(tc.expected[i], result) { | ||
| t.Errorf("item %d: expected %+v, got %+v", i, tc.expected[i], result) | ||
| } | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestBatchPutItemsError(t *testing.T) { | ||
| table := prepareTable(t) | ||
| ctx := context.TODO() | ||
|
|
||
| testCases := []struct { | ||
| title string | ||
| inputs []dynago.BatchPutItemsInput | ||
| expectError bool | ||
| }{ | ||
| { | ||
| title: "empty partition key should error", | ||
| inputs: []dynago.BatchPutItemsInput{ | ||
| { | ||
| PartitionKeyValue: dynago.StringValue(""), | ||
| SortKeyValue: dynago.StringValue("profile_1"), | ||
| Item: BatchTestRecord{ | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| }, | ||
| }, | ||
| expectError: true, | ||
| }, | ||
| { | ||
| title: "empty sort key should error", | ||
| inputs: []dynago.BatchPutItemsInput{ | ||
| { | ||
| PartitionKeyValue: dynago.StringValue("user_1"), | ||
| SortKeyValue: dynago.StringValue(""), | ||
| Item: BatchTestRecord{ | ||
| ID: "1", | ||
| Name: "John Doe", | ||
| Age: 30, | ||
| }, | ||
| }, | ||
| }, | ||
| expectError: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range testCases { | ||
| t.Run(tc.title, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| err := table.BatchPutItems(ctx, tc.inputs) | ||
| if tc.expectError && err == nil { | ||
| t.Fatalf("expected error but got none") | ||
| } | ||
| if !tc.expectError && err != nil { | ||
| t.Fatalf("unexpected error: %s", err) | ||
| } | ||
| }) | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.