-
Notifications
You must be signed in to change notification settings - Fork 952
Serialization optimization for DDB enhanced Client #6507
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
3724328
adding strategy serialization optimization
RanVaknin 98df969
uncomment new codepath
RanVaknin ba98a32
refactor to use jackson directly
RanVaknin ab5c62c
use SdkJsonGenerator
RanVaknin 03538d1
Add test coverage
RanVaknin c477064
remove old toJson codepath
RanVaknin 3181608
refactor serialize to use jackson directly
RanVaknin 6b2036a
Refactor implementation
RanVaknin 121be88
Refactor Serializer to share factory
RanVaknin 33037e1
Fix checkstyle
RanVaknin bdec395
Refactoring based on comments from maintainer
RanVaknin 4bb87e5
uncomment code
RanVaknin ea12b80
Fix maintainer comments
RanVaknin 60e7fe6
Add changelog
RanVaknin e99df4c
Add fixture tests to cover binary handling edge cases
RanVaknin 7ee590d
Update dependencies to use new jackson
RanVaknin fd8a72b
trigger PR diff refresh
RanVaknin d66dbf5
Merge remote-tracking branch 'origin/master' into rvaknin/optimize-to…
RanVaknin d1789e7
Add missing dependencies
RanVaknin ccb847b
Fix checkstyle
RanVaknin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.changes/next-release/feature-AmazonDynamoDBEnhancedClient-798234c.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "type": "feature", | ||
| "category": "Amazon DynamoDB Enhanced Client", | ||
| "contributor": "", | ||
| "description": "Optimize implementation of the toJson() and getJson() used by the DDB Enhanced Client Serialization codepaths" | ||
| } | ||
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
121 changes: 121 additions & 0 deletions
121
...va/software/amazon/awssdk/enhanced/dynamodb/internal/document/DocumentJsonSerializer.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"). | ||
| * You may not use this file except in compliance with the License. | ||
| * A copy of the License is located at | ||
| * | ||
| * http://aws.amazon.com/apache2.0 | ||
| * | ||
| * or in the "license" file accompanying this file. This file is distributed | ||
| * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
| * express or implied. See the License for the specific language governing | ||
| * permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package software.amazon.awssdk.enhanced.dynamodb.internal.document; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.OutputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import java.util.Map; | ||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
| import software.amazon.awssdk.core.SdkBytes; | ||
| import software.amazon.awssdk.protocols.json.SdkJsonGenerator; | ||
| import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | ||
| import software.amazon.awssdk.thirdparty.jackson.core.JsonFactory; | ||
| import software.amazon.awssdk.thirdparty.jackson.core.JsonGenerator; | ||
|
|
||
| /** | ||
| * JSON serializer for DynamoDB Enhanced Client document operations. | ||
| */ | ||
| @SdkInternalApi | ||
| final class DocumentJsonSerializer { | ||
| private static final JsonFactory JSON_FACTORY = new JsonFactory() { | ||
| @Override | ||
| public JsonGenerator createGenerator(OutputStream out) throws IOException { | ||
| return super.createGenerator(out).enable(JsonGenerator.Feature.COMBINE_UNICODE_SURROGATES_IN_UTF8); | ||
| } | ||
| }; | ||
|
|
||
| private DocumentJsonSerializer() { | ||
| } | ||
|
|
||
| public static String serializeAttributeValueMap(Map<String, AttributeValue> map) { | ||
| SdkJsonGenerator jsonGen = new SdkJsonGenerator(JSON_FACTORY, "application/json"); | ||
|
|
||
| jsonGen.writeStartObject(); | ||
| map.forEach((key, value) -> { | ||
| jsonGen.writeFieldName(key); | ||
| serializeAttributeValue(jsonGen, value); | ||
| }); | ||
| jsonGen.writeEndObject(); | ||
|
|
||
| return new String(jsonGen.getBytes(), StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| public static String serializeSingleAttributeValue(AttributeValue av) { | ||
| SdkJsonGenerator jsonGen = new SdkJsonGenerator(JSON_FACTORY, "application/json"); | ||
| serializeAttributeValue(jsonGen, av); | ||
| return new String(jsonGen.getBytes(), StandardCharsets.UTF_8); | ||
| } | ||
|
|
||
| public static void serializeAttributeValue(SdkJsonGenerator generator, AttributeValue av) { | ||
| switch (av.type()) { | ||
| case NUL: | ||
| generator.writeNull(); | ||
| break; | ||
| case S: | ||
| generator.writeValue(av.s()); | ||
| break; | ||
| case N: | ||
| generator.writeNumber(av.n()); | ||
| break; | ||
| case BOOL: | ||
| generator.writeValue(av.bool()); | ||
| break; | ||
| case B: | ||
| generator.writeValue(av.b().asByteBuffer()); | ||
| break; | ||
| case L: | ||
| generator.writeStartArray(); | ||
| for (AttributeValue item : av.l()) { | ||
| serializeAttributeValue(generator, item); | ||
| } | ||
| generator.writeEndArray(); | ||
| break; | ||
| case M: | ||
| generator.writeStartObject(); | ||
| for (Map.Entry<String, AttributeValue> entry : av.m().entrySet()) { | ||
| generator.writeFieldName(entry.getKey()); | ||
| serializeAttributeValue(generator, entry.getValue()); | ||
| } | ||
| generator.writeEndObject(); | ||
| break; | ||
| case SS: | ||
| generator.writeStartArray(); | ||
| for (String s : av.ss()) { | ||
| generator.writeValue(s); | ||
| } | ||
| generator.writeEndArray(); | ||
| break; | ||
| case NS: | ||
| generator.writeStartArray(); | ||
| for (String n : av.ns()) { | ||
| generator.writeNumber(n); | ||
| } | ||
| generator.writeEndArray(); | ||
| break; | ||
| case BS: | ||
| generator.writeStartArray(); | ||
| for (SdkBytes b : av.bs()) { | ||
| generator.writeValue(b.asByteBuffer()); | ||
| } | ||
| generator.writeEndArray(); | ||
| break; | ||
| default: | ||
| throw new IllegalArgumentException("Unsupported AttributeValue type: " + av.type()); | ||
| } | ||
| } | ||
|
|
||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.