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

SQL: Fix parsing of dates with milliseconds #30419

Merged
merged 3 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ Rollup::
* Validate timezone in range queries to ensure they match the selected job when
searching ({pull}30338[#30338])

SQL::
* Fix parsing of Dates containing milliseconds ({pull}30419[#30419])

[float]
=== Regressions
Fail snapshot operations early when creating or deleting a snapshot on a repository that has been
Expand Down Expand Up @@ -201,6 +204,8 @@ Rollup::
* Validate timezone in range queries to ensure they match the selected job when
searching ({pull}30338[#30338])

SQL::
* Fix parsing of Dates containing milliseconds ({pull}30419[#30419])

Allocation::

Expand Down Expand Up @@ -241,6 +246,9 @@ Reduce the number of object allocations made by {security} when resolving the in

Respect accept header on requests with no handler ({pull}30383[#30383])

SQL::
* Fix parsing of Dates containing milliseconds ({pull}30419[#30419])

//[float]
//=== Regressions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
*/
public abstract class DataTypeConversion {

private static final DateTimeFormatter UTC_DATE_FORMATTER = ISODateTimeFormat.dateTimeNoMillis().withZoneUTC();
private static final DateTimeFormatter UTC_DATE_FORMATTER = ISODateTimeFormat.dateOptionalTimeParser().withZoneUTC();

/**
* Returns the type compatible with both left and right types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,15 @@ public void testConversionToDate() {
Conversion conversion = DataTypeConversion.conversionFor(DataType.KEYWORD, to);
assertNull(conversion.convert(null));

// TODO we'd like to be able to optionally parse millis here I think....
assertEquals(new DateTime(1000L, DateTimeZone.UTC), conversion.convert("1970-01-01T00:00:01Z"));
assertEquals(new DateTime(1483228800000L, DateTimeZone.UTC), conversion.convert("2017-01-01T00:00:00Z"));
assertEquals(new DateTime(18000000L, DateTimeZone.UTC), conversion.convert("1970-01-01T00:00:00-05:00"));

// double check back and forth conversion
DateTime dt = DateTime.now(DateTimeZone.UTC);
Conversion forward = DataTypeConversion.conversionFor(DataType.DATE, DataType.KEYWORD);
Conversion back = DataTypeConversion.conversionFor(DataType.KEYWORD, DataType.DATE);
assertEquals(dt, back.convert(forward.convert(dt)));
Exception e = expectThrows(SqlIllegalArgumentException.class, () -> conversion.convert("0xff"));
assertEquals("cannot cast [0xff] to [Date]:Invalid format: \"0xff\" is malformed at \"xff\"", e.getMessage());
}
Expand Down