-
Notifications
You must be signed in to change notification settings - Fork 647
feat(dynamodb): add batch get item paginators for low level and document client #7522
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
Draft
cipak
wants to merge
5
commits into
aws:main
Choose a base branch
from
cipak:feat/paginate-batch-get-item
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f8d5a04
feat(dynamodb): add batch get item paginators for low level and docum…
cipak c9b2830
improve tsdoc
cipak 05edaf1
add tests (positive and negative)
cipak 1af69d0
explain the tests in a comment
cipak aa4f6aa
rename batch paginator functions to avoid future collisions with thei…
cipak 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { type DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
|
|
||
| import { BatchGetCommand, BatchGetCommandInput, BatchGetCommandOutput } from "../commands/BatchGetCommand"; | ||
| import { DynamoDBDocumentClient } from "../DynamoDBDocumentClient"; | ||
|
|
||
| /** | ||
| * Async generator that issues {@link BatchGetCommand}s repeatedly until all keys are processed or an error response is received. | ||
| * | ||
| * @public | ||
| * | ||
| * @see {@link paginatedBatchGet} for a variant that uses the {@link DynamoDBClient | low level DynamoDB client}. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * const client = new DynamoDBClient(); | ||
| * const docClient = DynamoDBDocumentClient.from(client); | ||
| * const input: BatchGetCommandInput = { | ||
| * RequestItems: { | ||
| * table1: Keys: [...], | ||
| * table2: Keys: [...], | ||
| * } | ||
| * }; | ||
| * | ||
| * let pageNumber = 1; | ||
| * for await (const page of paginateBatchGet({ client: docClient }, input)) { | ||
| * console.log("page:", pageNumber++); | ||
| * console.log("items:", page.Responses); | ||
| * console.log("unprocessed:", page.UnprocessedKeys); // will be returned in the next page(s) | ||
| * } | ||
| * ``` | ||
| */ | ||
| export async function* paginatedBatchGet( | ||
| config: { | ||
| client: DynamoDBDocumentClient; | ||
| }, | ||
| input: BatchGetCommandInput | ||
| ): AsyncGenerator<BatchGetCommandOutput> { | ||
| let RequestItems = input.RequestItems; | ||
|
|
||
| while (RequestItems && Object.keys(RequestItems).length > 0) { | ||
| const cmd = new BatchGetCommand({ ...input, RequestItems }); | ||
| const response = await config.client.send(cmd); | ||
| RequestItems = { ...response.UnprocessedKeys }; | ||
|
|
||
| yield response; | ||
| } | ||
| } |
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
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,40 @@ | ||
| import { BatchGetItemCommand, BatchGetItemCommandInput, DynamoDBClient } from "@aws-sdk/client-dynamodb"; | ||
| import { type DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"; | ||
|
|
||
| /** | ||
| * Async generator that issues {@link BatchGetItemCommand}s repeatedly until all keys are processed or an error response is received. | ||
kuhe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| * | ||
| * @public | ||
| * | ||
| * @see {@link paginatedBatchGetItem} for a variant that uses the {@link DynamoDBDocumentClient | DynamoDB document client}. | ||
| * | ||
| * @example | ||
| * | ||
| * ```typescript | ||
| * const client = new DynamoDBClient(); | ||
| * const input: BatchGetCommandInput = { | ||
| * RequestItems: { | ||
| * table1: Keys: [...], | ||
| * table2: Keys: [...], | ||
| * } | ||
| * }; | ||
| * | ||
| * let pageNumber = 1; | ||
| * for await (const page of paginateBatchGetItem({ client }, input)) { | ||
| * console.log("page:", pageNumber++); | ||
| * console.log("items:", page.Responses); | ||
| * console.log("unprocessed:", page.UnprocessedKeys); // will be returned in the next page(s) | ||
| * } | ||
| * ``` | ||
| */ | ||
| export async function* paginatedBatchGetItem(config: { client: DynamoDBClient }, input: BatchGetItemCommandInput) { | ||
| let RequestItems = input.RequestItems; | ||
|
|
||
| while (RequestItems && Object.keys(RequestItems).length > 0) { | ||
| const cmd = new BatchGetItemCommand({ ...input, RequestItems }); | ||
| const response = await config.client.send(cmd); | ||
| RequestItems = { ...response.UnprocessedKeys }; | ||
|
|
||
| yield response; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this paginator should be placed with the client rather than util-dynamodb, but named in a way that prevents collisions between it and the generated paginators
perhaps
export async function* customPaginateBatchGetItem(...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as for the naming, we cannot use the same pattern as the generated paginator because it would break backwards compatibility if the type signature changes between the hand-written and generated paginator.
it can be named something subtly different rather than "customPaginateBatchGetItem", perhaps "paginatedBatchGetItem"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the functions as suggested (paginatedBatchGetItem for the low-level client and paginatedBatchGet for document client).
regarding moving the low-level client paginator from util-dynamodb to client-dynamodb, I'll leave that part to the next developer, as today I am transitioning off the project.