Skip to content
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

feat(lib-dynamodb): large number handling #5427

Merged
merged 6 commits into from
Oct 31, 2023

Conversation

kuhe
Copy link
Contributor

@kuhe kuhe commented Oct 27, 2023

Issue

fixes #5363

Description

This PR introduces an input side container for large/precise numbers not representable by the Native JS number type.

  const dynamodb = new DynamoDB({ region: "us-west-2", maxAttempts: 10 });
  const doc = DynamoDBDocument.from(dynamodb, {
    unmarshallOptions: {
      wrapNumbers: true,
    },
  });

To write a large or precise number:

import { DynamoDB } from "@aws-sdk/client-dynamodb";
import { NumberValue, DynamoDBDocument } from "@aws-sdk/lib-dynamodb";

// note, the client will not validate the acceptability of the number.
// it is only to preserve its precise representation.
DynamoDBDocument.from(new DynamoDB({})).put({
  Item: {
    id: NumberValue.from("1000000000000000000000.000000000001")
  }
});

(You can also use this wrapper for small numbers, but that is optional).
e.g.

new Set([
  1, "1234567890", 2, 3, 4
].map(NumberValue.from));

To read large or precise numbers, set

    unmarshallOptions: {
      wrapNumbers: true,
    },

as shown above. All numbers will be returned in the NumberValue wrapper.

Testing

new unit and e2e tests

Checklist

  • update lib-dynamodb documentation
  • If you wrote E2E tests, are they resilient to concurrent I/O?
  • If adding new public functions, did you add the @public tag and enable doc generation on the package?

@kuhe kuhe requested a review from a team as a code owner October 27, 2023 20:54
@kuhe kuhe force-pushed the feat/dynamodb-big-numbers branch from 39036d7 to 2ca27ed Compare October 31, 2023 19:28
@kuhe kuhe merged commit 4c7fe9c into aws:main Oct 31, 2023
2 checks passed
@kuhe kuhe deleted the feat/dynamodb-big-numbers branch October 31, 2023 20:48
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(lib-dynamodb): DocumentClient should handle i/o of large numbers e.g. BigInt
2 participants