You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "YufeiLiu (Jira)" <ji...@apache.org> on 2020/04/02 12:42:00 UTC
[jira] [Comment Edited] (FLINK-16938) SqlTimestamp has lag when
convert long to Timestamp
[ https://issues.apache.org/jira/browse/FLINK-16938?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17073683#comment-17073683 ]
YufeiLiu edited comment on FLINK-16938 at 4/2/20, 12:41 PM:
------------------------------------------------------------
[~jark] Sorry I didn't describe clearly. That code can run, but the result is results are 8 hours early because my timezone is GMT+8.
* cast long to SqlTimestamp: SqlTimestamp.fromEpochMillis()
* cast SqlTimestamp to Timestamp: {{Timestamp.valueOf(toLocalDateTime())}}
{{toLocalDateTime}} actual return datetime in UTC, but Timestamp.valueOf treat it in system timezone.
I think type TIMESTAMP_WITH_OUT_TIME_ZONE is effect by system timezone isn't ideal.
The next comment I want to explain a time attribute only support TIMESTAMP(3), I cant declare AS {{TIMESTAMP(3) WITH LOCAL TIME ZONE}}.
was (Author: liuyufei):
[~jark] Sorry I didn't describe clearly. That code can run, but the result is results are 8 hours early because my timezone is GMT+8.
* cast long to SqlTimestamp: SqlTimestamp.fromEpochMillis()
* cast SqlTimestamp to Timestamp: {{Timestamp.valueOf(toLocalDateTime())}}
{{toLocalDateTime}} actual return datetime in UTC, but Timestamp.valueOf treat it in system timezone.
I think type TIMESTAMP_WITH_OUT_TIME_ZONE is effect by system timezone is nonideal.
The next comment I want to explain a time attribute only support TIMESTAMP(3), I cant declare AS {{TIMESTAMP(3) WITH LOCAL TIME ZONE}}.
> SqlTimestamp has lag when convert long to Timestamp
> ---------------------------------------------------
>
> Key: FLINK-16938
> URL: https://issues.apache.org/jira/browse/FLINK-16938
> Project: Flink
> Issue Type: Bug
> Components: Table SQL / Planner
> Affects Versions: 1.10.0
> Reporter: YufeiLiu
> Priority: Major
>
> When I set rowtime attribute by using expression 'column.rowtime' , and result type is sql.Timestamp, the result will have lag which is equals with default timezone offset.
> {code:java}
> tEnv.fromDataStream(stream, "user_action_time.rowtime, user_name, data");
> {code}
> I look into the conversion logic, the field was go through 'long -> SqlTimestamp -> Timestamp' conversion.
> {code:java}
> long from = System.currentTimeMillis();
> long to = SqlTimestamp
> .fromEpochMillis(from)
> .toTimestamp()
> .getTime();
> {code}
> The result is {{from!=to}}. In {{SqlTimestamp.toTimestamp()}} using {{Timestamp.valueOf(LocalDateTime dateTime)}} which is contain timezone infomation, will casue time lag.
> From Timestamp to Timestamp not have this issue, but convert Datastream to Table is use StreamRecord.timestamp as rowtime field.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)