-
Notifications
You must be signed in to change notification settings - Fork 1k
Migrate AttributeValue #7199
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
Open
RanVaknin
wants to merge
6
commits into
feature/master/DDB-mapperv2
Choose a base branch
from
rvaknin/migrate-converters
base: feature/master/DDB-mapperv2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Migrate AttributeValue #7199
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d6a8beb
Add net new coverage to fill in testing gaps with v1
RanVaknin 56be1cd
Migrate to v2 AttributeValue
RanVaknin 9f5f4e6
Fix comments, ubstub operations to reduce review burden
RanVaknin 433befe
Fix ByteBuffer to be mutable and fix marshaller exception handling in…
RanVaknin 1ed9ca4
Remove fully qualified imports
RanVaknin 45bdadf
Fix header
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
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
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
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
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
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
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
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
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
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
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
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
131 changes: 131 additions & 0 deletions
131
...dynamodb-mapper/src/main/java/software/amazon/awssdk/mapper/dynamodb/MapperDateUtils.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,131 @@ | ||
| /* | ||
| * 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.mapper.dynamodb; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
|
|
||
| import org.joda.time.DateTimeZone; | ||
| import org.joda.time.format.DateTimeFormat; | ||
| import org.joda.time.format.DateTimeFormatter; | ||
| import org.joda.time.format.ISODateTimeFormat; | ||
| import org.joda.time.tz.FixedDateTimeZone; | ||
|
|
||
| import software.amazon.awssdk.annotations.SdkInternalApi; | ||
|
|
||
| /** | ||
| * A thin port of only the ISO-8601 parse/format methods of the v1 {@code com.amazonaws.util.DateUtils} | ||
| * that the mapper's converter layer uses, kept on the same Joda-Time formatters to preserve byte-for-byte | ||
| * compatibility with dates written by the v1 mapper. | ||
| */ | ||
| @SdkInternalApi | ||
| public final class MapperDateUtils { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are there tests for this? |
||
|
|
||
| private static final DateTimeZone GMT = new FixedDateTimeZone("GMT", "GMT", 0, 0); | ||
| private static final long MILLI_SECONDS_OF_365_DAYS = 365L * 24 * 60 * 60 * 1000; | ||
|
|
||
| /** ISO 8601 format. */ | ||
| private static final DateTimeFormatter ISO8601_DATE_FORMAT = | ||
| ISODateTimeFormat.dateTime().withZone(GMT); | ||
|
|
||
| /** Alternate ISO 8601 format without fractional seconds. */ | ||
| private static final DateTimeFormatter ALTERNATE_ISO8601_DATE_FORMAT = | ||
| DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'").withZone(GMT); | ||
|
|
||
| /** ISO 8601 format with a UTC offset. */ | ||
| private static final DateTimeFormatter ISO8601_DATE_FORMAT_WITH_OFFSET = | ||
| DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZZ"); | ||
|
|
||
| private static final List<DateTimeFormatter> ALTERNATE_ISO8601_FORMATTERS = Arrays.asList( | ||
| ALTERNATE_ISO8601_DATE_FORMAT, ISO8601_DATE_FORMAT_WITH_OFFSET); | ||
|
|
||
| private MapperDateUtils() { | ||
| } | ||
|
|
||
| /** | ||
| * Parses the specified date string as an ISO 8601 date and returns the {@link Date} object. | ||
| * | ||
| * @param dateStringOrig the date string to parse | ||
| * @return the parsed {@link Date} object | ||
| */ | ||
| public static Date parseISO8601Date(final String dateStringOrig) { | ||
| String dateString = dateStringOrig; | ||
|
|
||
| // For EC2 Spot Fleet. | ||
| if (dateString.endsWith("+0000")) { | ||
| dateString = dateString | ||
| .substring(0, dateString.length() - 5) | ||
| .concat("Z"); | ||
| } | ||
|
|
||
| // https://github.com/aws/aws-sdk-java/issues/233 | ||
| String temp = tempDateStringForJodaTime(dateString); | ||
| try { | ||
| if (temp.equals(dateString)) { | ||
| // Normal case: nothing special here | ||
| return new Date(ISO8601_DATE_FORMAT.parseMillis(dateString)); | ||
| } | ||
| // Handling edge case: | ||
| // Joda-time can only handle up to year 292278993 but we are given | ||
| // 292278994; So we parse the date string by first adjusting | ||
| // the year to 292278993. Then we add 1 year back afterwards. | ||
| final long milliLess365Days = ISO8601_DATE_FORMAT.parseMillis(temp); | ||
| final long milli = milliLess365Days + MILLI_SECONDS_OF_365_DAYS; | ||
| if (milli < 0) { // overflow! | ||
| // re-parse the original date string using JodaTime so as to | ||
| // throw an exception with a consistent message | ||
| return new Date(ISO8601_DATE_FORMAT.parseMillis(dateString)); | ||
| } | ||
| return new Date(milli); | ||
| } catch (IllegalArgumentException e) { | ||
| for (DateTimeFormatter dateTimeFormatter : ALTERNATE_ISO8601_FORMATTERS) { | ||
| try { | ||
| // If the first ISO 8601 parser didn't work, try the alternate | ||
| // version which doesn't include fractional seconds | ||
| return new Date(dateTimeFormatter.parseMillis(dateString)); | ||
| } catch (Exception oops) { | ||
| // ignore | ||
| } | ||
| } | ||
|
|
||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Formats the specified date as an ISO 8601 string. | ||
| * | ||
| * @param date the date to format | ||
| * @return the ISO 8601 string representing the specified date | ||
| */ | ||
| public static String formatISO8601Date(final Date date) { | ||
| return ISO8601_DATE_FORMAT.print(date.getTime()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a date string with the prefix temporarily substituted, if applicable, so that | ||
| * JodaTime can handle it. Otherwise, if not applicable, the original date string is returned. | ||
| * | ||
| * <p>See https://github.com/aws/aws-sdk-java/issues/233</p> | ||
| */ | ||
| private static String tempDateStringForJodaTime(final String dateString) { | ||
| final String fromPrefix = "292278994-"; | ||
| final String toPrefix = "292278993-"; | ||
| return dateString.startsWith(fromPrefix) | ||
| ? toPrefix + dateString.substring(fromPrefix.length()) | ||
| : dateString; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to keep using Joda time for this internal class?