Skip to content

Replace legacy patameter AttributesToGet with ProjectionExpression an…#4343

Open
aanton-git wants to merge 8 commits intoaws:developmentfrom
aanton-git:features/replace-legacy-psrsmeter-GetItem
Open

Replace legacy patameter AttributesToGet with ProjectionExpression an…#4343
aanton-git wants to merge 8 commits intoaws:developmentfrom
aanton-git:features/replace-legacy-psrsmeter-GetItem

Conversation

@aanton-git
Copy link
Copy Markdown
Contributor

@aanton-git aanton-git commented Feb 26, 2026

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
  • development branch
image
  • feature branch - aws client
image
2. Mocked client
  • development branch
image
  • feature branch
image

Breaking Changes Assessment

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • [x ] New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • [ x] I have added tests to cover my changes
  • [ x] All new and existing tests passed

@dscpinheiro dscpinheiro changed the base branch from main to development February 26, 2026 16:04
@aanton-git aanton-git marked this pull request as ready for review March 5, 2026 13:59
@jnunn-aws jnunn-aws requested a review from normj March 5, 2026 17:37
@peterrsongg peterrsongg requested a review from Copilot March 19, 2026 04:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 GetItem using ProjectionExpression instead of AttributesToGet.
  • Introduced shared get-item request plumbing (BaseGetItemDocumentOperationRequest + an internal request type) and updated the GetItemPipeline to 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.

Comment thread generator/.DevConfigs/6ef51ef2-c049-4a0d-bb08-e672bf81ceb5.json Outdated
Comment thread generator/.DevConfigs/6ef51ef2-c049-4a0d-bb08-e672bf81ceb5.json Outdated
Comment thread sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs
Comment thread sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs Outdated
Comment thread sdk/src/Services/DynamoDBv2/Custom/DocumentModel/DocumentOperationPipeline.cs Outdated
"services": [
{
"serviceName": "DynamoDBv2",
"type": "patch",
Comment thread sdk/src/Services/DynamoDBv2/Custom/DataModel/InternalModel.cs Outdated
Comment thread sdk/test/Services/DynamoDBv2/IntegrationTests/DataModelTests.cs Outdated
@aanton-git aanton-git force-pushed the features/replace-legacy-psrsmeter-GetItem branch from d802569 to 3cda990 Compare April 16, 2026 12:17
Copy link
Copy Markdown
Contributor

@dscpinheiro dscpinheiro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread sdk/src/Services/DynamoDBv2/Custom/DataModel/Context.cs
@aanton-git aanton-git requested review from a team as code owners May 5, 2026 07:59
@aanton-git aanton-git requested review from dscpinheiro and peterrsongg and removed request for a team May 5, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants