feat: add DynamoDB query support to DynamoDBRead - #694
Open
nasudadada wants to merge 2 commits into
Open
Conversation
Extend DynamoDBRead to use the DynamoDB query operation when partition_key/partition_value (and optionally sort_key/sort_value) are specified, instead of always scanning the whole table. Falls back to scan when no key is specified, so existing scenarios keep working unchanged. Closes BrainPad#529
DynamoDBRead.Arguments inherited the required `region: str` from BaseAws.Arguments, so omitting region raised a pydantic ValidationError even though the docs describe it as optional (falls back to the default AWS region). Override it as optional, same as BaseS3.Arguments does.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Brief
Extend
DynamoDBReadto support the DynamoDBqueryoperation in addition toscan,so users can efficiently retrieve items by partition key (and optionally sort key)
instead of always scanning the whole table.
Closes #529
Key Changes
partition_key/partition_value/sort_key/sort_valuearguments toDynamoDBReadpartition_key/partition_valueare specified, aqueryoperation is used(equality condition only, optionally narrowed by
sort_key/sort_value)scan— fully backward compatible withexisting scenarios
DynamoDBReadto the pydanticArgumentspattern (table_name/file_nameare now required fields,
file_formatis aLiteral["csv", "jsonl"])model_validatorto reject invalid combinations (e.g.sort_keywithoutpartition_key, or a key name given without its matching value)_paginate()generator used by both_scan_tableand the new_query_table, to avoid duplicating theLastEvaluatedKeypagination loopTest
Confirmed
tests/scenario/extract/test_aws.pycovering: scan(regression), query by partition key only, query by partition key + sort key,
pagination for both scan and query, and the new validation error cases
pflake8,black --check,isort --check,bandit --severity-level high,lint-imports,pytest --cov