Replace legacy patameter AttributesToGet with ProjectionExpression an…#4343
Replace legacy patameter AttributesToGet with ProjectionExpression an…#4343aanton-git wants to merge 8 commits intoaws:developmentfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates the DynamoDB DataModel LoadAsync path away from the legacy AttributesToGet parameter and toward the modern expression-based API by constructing and applying a ProjectionExpression (with ExpressionAttributeNames) when issuing GetItem requests.
Changes:
- Updated the async load pipeline to issue
GetItemusingProjectionExpressioninstead ofAttributesToGet. - Introduced shared get-item request plumbing (
BaseGetItemDocumentOperationRequest+ an internal request type) and updated theGetItemPipelineto map/validate both request shapes. - Added DynamoDBv2 integration tests intended to exercise the new projection-expression load flow.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/test/Services/DynamoDBv2/IntegrationTests/DataModelTests.cs | Adds new integration tests for LoadAsync behavior under the projection-expression flow. |
| sdk/src/Services/DynamoDBv2/Custom/DocumentModel/Table.cs | Adjusts internal GetItemHelperAsync to accept the new base request type used by the pipeline. |
| sdk/src/Services/DynamoDBv2/Custom/DocumentModel/InternalDocumentOperationRequest.cs | Adds an internal get-item request type using low-level AttributeValue keys for the DataModel path. |
| sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentOperationRequest.cs | Introduces BaseGetItemDocumentOperationRequest and updates GetItemDocumentOperationRequest to inherit from it. |
| sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentOperationPipeline.cs | Updates GetItemPipeline to operate on the new base request and map/validate based on concrete request type. |
| sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs | Builds a reusable ProjectionExpression on ItemStorageConfig while keeping AttributesToGet for non-migrated flows. |
| sdk/src/Services/DynamoDBv2/Custom/DataModel/ContextInternal.cs | Minor using reordering. |
| sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs | Updates LoadHelperAsync to use the new internal get-item request + ProjectionExpression. |
| generator/.DevConfigs/6ef51ef2-c049-4a0d-bb08-e672bf81ceb5.json | Adds a DevConfig entry for the DynamoDBv2 change. |
Comments suppressed due to low confidence (1)
sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentOperationRequest.cs:48
- Introducing the new public BaseGetItemDocumentOperationRequest type expands the public DocumentModel API and also changes GetItemDocumentOperationRequest’s inheritance chain. If the intent is only to support internal DataModel plumbing, consider using an internal interface/composition instead to avoid growing the public surface area (which impacts versioning/back-compat commitments).
public class GetItemDocumentOperationRequest : BaseGetItemDocumentOperationRequest
{
/// <summary>
/// Gets or sets the key identifying the item in the table.
/// All key components (partition and sort key, if the table has one) must be provided.
/// </summary>
public IDictionary<string, DynamoDBEntry> Key { get; set; }
}
/// <summary>
/// Abstract base class for DynamoDB GetItem document operation requests.
/// Provides shared configuration for retrieving a single item using the expression-based API.
/// Legacy parameters (e.g., <c>AttributesToGet</c>) are not supported; use <c>ProjectionExpression</c> instead.
/// Extended by <see cref="GetItemDocumentOperationRequest"/>
/// </summary>
public abstract class BaseGetItemDocumentOperationRequest : DocumentOperationRequest
{
/// <summary>
/// Gets or sets the projection expression specifying which attributes should be retrieved.
/// If null, all attributes are returned.
/// </summary>
public Expression ProjectionExpression { get; set; }
/// <summary>
/// Gets or sets the consistent read flag.
/// Strongly consistent reads are only valid for tables and local secondary indexes.
/// </summary>
public bool ConsistentRead { get; set; }
You can also share your feedback on Copilot code review. Take the survey.
| "services": [ | ||
| { | ||
| "serviceName": "DynamoDBv2", | ||
| "type": "patch", |
…d ExpressionAttributesName in LoadAsync flow
d802569 to
3cda990
Compare
dscpinheiro
left a comment
There was a problem hiding this comment.
Could you update the PR description to expand on the benchmark results?
Maybe it's me but I found it hard to read the image since the rows weren't in the same order... It also looks like for some cases the allocations slightly increased.
Description
Migrate the LoadAsync flow to use DynamoDB’s modern projection-based API by replacing the legacy AttributesToGet parameter with ProjectionExpression and ExpressionAttributeNames.
Motivation and Context
LoadAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType) flows into GetItemHelperAsync(Key, GetItemOperationConfig, CancellationToken), which still uses the legacy AttributesToGet. AWS recommends ProjectionExpression + ExpressionAttributeNames instead. Update the request construction to use projection expressions and stop emitting AttributesToGet.
Current Flow
• Context.Async.cs → LoadHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType)
• Context.cs → LoadHelperAsync<[DynamicallyAccessedMembers(InternalConstants.DataModelModeledType) builds AttributesToGet
• Table.cs → GetItemHelperAsync(Key, GetItemOperationConfig, CancellationToken) sets AttributesToGet
Testing
Benchmark results
1. Real AWS client
2. Mocked client
Breaking Changes Assessment
Screenshots (if appropriate)
Types of changes
Checklist