luocooong opened a new issue #2298:
URL: https://github.com/apache/drill/issues/2298
**Is your feature request related to a problem? Please describe.**
Support the UTC formatter in the JSON Reader
**Describe the solution you'd like**
optional 1 :
- use a few of the most popular formatter and the try-catch
- minimal changes
example :
```java
LocalDateTime ldt;
try {
OffsetDateTime originalDateTime =
OffsetDateTime.parse(parser.getValueAsString(), DateUtility.isoFormatTimeStamp);
ldt = originalDateTime.toLocalDateTime();
} catch (DateTimeParseException e) {
ldt = LocalDateTime.parse(parser.getValueAsString(),
DateUtility.utcFormatDateTime); // "yyyy-MM-dd'T'HH:mm:ss'Z'"
} catch (DateTimeParseException e) {
ldt = LocalDateTime.parse(parser.getValueAsString(),
DateUtility.utcFormatTimeStamp); // "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
}
OffsetDateTime utcDateTime = OffsetDateTime.of(ldt, ZoneOffset.UTC);
```
optional 2 :
- allow the user to define the UTC formatter use the `ALTER SESSION SET`
syntax.
- _not sure the framework support to extend this feature._
example (Dummy) :
```
ALTER SESSION SET `store.json.date_formatter` = "yyyy-MM-dd'T'HH:mm:ss'Z'"
```
```java
LocalDateTime ldt;
if (hasUTCKeyword(parser.getValueAsString()) { // value.indexOf('T') > 0 &
value.indexOf('Z') > value.indexOf('T')
ldt = LocalDateTime.parse(parser.getValueAsString(),
session_date_formatter);
} else {
ldt = OffsetDateTime.parse(parser.getValueAsString(),
session_date_formatter).toLocalDateTime();
}
```
**Describe alternatives you've considered**
NONE
**Additional context**
When the date value as the ISODate (without the timezone, or called 0
timezone) store in mongo and set the `store.mongo.bson.record.reader` to false:
```json
{
"_id" : ObjectId("5da7760149b3f000195cabb"),
"date" : ISODate("2019-09-24T20:06:56Z")
}
```
Drill got the error stack error :
```
Caused by: java.lang.Exception: Text '2019-09-30T20:47:43Z' could not be
parsed at index 19
```
Because the `OffsetDateTime` parse the date string use the fixed formatter
`yyyy-MM-dd'T'HH:mm:ss.SSSXX`. Then, the OffsetDateTime is not allowed to
accept the UTC formatter `***T***Z` (or called 0 timezone) :
example 1:
```
yyyy-MM-dd'T'HH:mm:ss.SSS'Z'
```
example 2:
```
yyyy-MM-dd'T'HH:mm:ss'Z'
```
Linked resource :
https://github.com/apache/drill/blob/39b565f112122734c080324fdcbef518ced16507/exec/java-exec/src/main/java/org/apache/drill/exec/vector/complex/fn/VectorOutput.java#L353-L357
https://github.com/apache/drill/blob/39b565f112122734c080324fdcbef518ced16507/exec/vector/src/main/java/org/apache/drill/exec/expr/fn/impl/DateUtility.java#L635-L635
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]