[
https://issues.apache.org/jira/browse/FLINK-19757?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17218907#comment-17218907
]
Jark Wu commented on FLINK-19757:
---------------------------------
> using LocalDateTime to represent the TIMESTAMP(TIMESTAMP WO LOCAL TIME ZONE )
> is not very proper
I don't agree with this. In semantic, {{LocalDateTime}} and TIMESTAMP is the
same, they both don't have time zone. The Apache community have a long
discussion for this, you can learn more from this
[doc|https://docs.google.com/document/d/1gNRww9mZJcHvUDCXklzjFEQGpefsuR_akCDfWsdE35Q/edit].
The logic of {{TimestampLocalDateTimeConverter}} is correct, as I said above,
there is no time zone involved when converting these two objects if the logical
type is {{TIMESTAMP}}.
Regarding to the sink side,
1) when the field is {{TIMESTAMP}} type, then you can get {{LocalDateTime}} via
{{TimestampData#toLocalDateTime()}} and write LocalDateTime to your external
system, if you want to convert LocalDateTime to string representation, you can
directly use {{LocalDateTime#toString()}} which doesn't require a time zone.
2) when the field is {{TIMESTAMP WITH LOCAL TIME ZONE}} type, then you can get
{{Instant}} via {{TimestampData#toInstant()}} and write Instant to your
external system, if you want to convert Instant to a string representation (it
requires a time zone), you can get the user defined time zone via
{{DynamicTableFactory.Context#getConfiguration.getString(TableConfigOptions#LOCAL_TIME_ZONE)}}
since 1.12.
Remember! {{LocalDateTime}} doesn't have time zone information! It's just a
year,month,day,hour,minute,seconds data value.
> TimeStampData can cause time inconsistent problem
> -------------------------------------------------
>
> Key: FLINK-19757
> URL: https://issues.apache.org/jira/browse/FLINK-19757
> Project: Flink
> Issue Type: Improvement
> Components: Table SQL / Runtime
> Affects Versions: 1.11.1
> Reporter: xiaogang zhou
> Priority: Major
> Labels: pull-request-available
>
> when we check jdk LocalDateTime code,we find that
>
> {code:java}
> // code placeholder
> public static LocalDateTime ofEpochSecond(long epochSecond, int nanoOfSecond,
> ZoneOffset offset) {
> Objects.requireNonNull(offset, "offset");
> NANO_OF_SECOND.checkValidValue(nanoOfSecond);
> long localSecond = epochSecond + offset.getTotalSeconds(); // overflow
> caught later
> long localEpochDay = Math.floorDiv(localSecond, SECONDS_PER_DAY);
> int secsOfDay = (int)Math.floorMod(localSecond, SECONDS_PER_DAY);
> LocalDate date = LocalDate.ofEpochDay(localEpochDay);
> LocalTime time = LocalTime.ofNanoOfDay(secsOfDay * NANOS_PER_SECOND +
> nanoOfSecond);
> return new LocalDateTime(date, time);
> }
> {code}
>
> offset.getTotalSeconds() they add the offset, but in the TimeStampData
> toLocalDateTime, we don't add a offset.
>
> I'd like to add a TimeZone.getDefault().getRawOffset() in the
> toLocalDateTime()
> and minus a TimeZone.getDefault().getRawOffset() in the
> fromLocalDateTime
--
This message was sent by Atlassian Jira
(v8.3.4#803005)