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

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

Closed
3 tasks done
alanb-sony opened this issue Oct 16, 2023 · 5 comments · Fixed by #5427
Closed
3 tasks done

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

alanb-sony opened this issue Oct 16, 2023 · 5 comments · Fixed by #5427
Labels
bug This issue is a bug. p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet. queued This issues is on the AWS team's backlog

Comments

@alanb-sony
Copy link

alanb-sony commented Oct 16, 2023

Checkboxes for prior research

Describe the bug

The following code:

const doc = DynamoDBDocument.from(new DynamoDB());
await doc.put({
  TableName: 'test',
  Item: { num: 1.23e100 },
});

Raises the error:

Error: Number 1.23e+100 is greater than Number.MAX_SAFE_INTEGER. Use BigInt.

We could change num to BigInt but it is actually a floating point value so we'd have to only convert large numbers, as our numbers are already stored as Number, changing them to BigInt isn't going to increase their precision

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.18.0

Reproduction Steps

const doc = DynamoDBDocument.from(new DynamoDB());
await doc.put({
  TableName: 'test',
  Item: { num: 1.23e100 },
});

Observed Behavior

An error is thrown:

Error: Number 1.23e+100 is greater than Number.MAX_SAFE_INTEGER. Use BigInt.

Expected Behavior

Large numbers should be stored in the database

Possible Solution

No response

Additional Information/Context

No response

@alanb-sony alanb-sony added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 16, 2023
@alanb-sony
Copy link
Author

Even converting a number to a BigInt isn't a trivial task as dynamo wont accept numbers with more than 38 digits of precision

@kuhe
Copy link
Contributor

kuhe commented Oct 16, 2023

For now, use the base DynamoDB client to put with large numbers.

@kuhe kuhe changed the title Unable to put large numbers through DocumentClient (lib-dynamodb): DocumentClient should handle i/o of large numbers e.g. BigInt Oct 16, 2023
@kuhe kuhe added p2 This is a standard priority issue queued This issues is on the AWS team's backlog and removed needs-triage This issue or PR still needs to be triaged. labels Oct 16, 2023
@kuhe kuhe added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Oct 31, 2023
@kuhe
Copy link
Contributor

kuhe commented Oct 31, 2023

A way to mark large or precise numbers for input and output will be included in the next release.

Instructions are at #5427 or https://github.com/aws/aws-sdk-js-v3/blob/main/lib/lib-dynamodb/README.md#large-numbers-and-numbervalue

@alanb-sony
Copy link
Author

This seems an odd solution to me? We can't construct NumberValue from a number so we have to do NumberValue.from(num.toString())?

I'm still not sure what the reasoning behind restricting the range of numbers is?

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 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. p2 This is a standard priority issue pending-release This issue will be fixed by an approved PR that hasn't been released yet. queued This issues is on the AWS team's backlog
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants