Re: confused about `TO_TIMESTAMP` document description

2021-06-10 Thread Tony Wei
Hi Leonard,

Thanks for confirmation. I have created the jira ticket [1]. The pull
request will be submitted later.

best regards,

[1] https://issues.apache.org/jira/browse/FLINK-22970

Leonard Xu  於 2021年6月10日 週四 下午8:58寫道:

> Hi,Tony
>
> > I found this code snippet [2] might be related to `TO_TIMESTAMP` udf,
> and seems like it won't set use any timezone configuration, so maybe the
> document might be wrong.
>
> Your analysis is right,the document is wrong, we should correct it.
>  Would you like to create an jira ticket and fix this?
>
> Best,
> Leonard
>
>


Re: confused about `TO_TIMESTAMP` document description

2021-06-10 Thread Leonard Xu
Hi,Tony

> I found this code snippet [2] might be related to `TO_TIMESTAMP` udf, and 
> seems like it won't set use any timezone configuration, so maybe the document 
> might be wrong.

Your analysis is right,the document is wrong, we should correct it.
 Would you like to create an jira ticket and fix this?

Best,
Leonard



confused about `TO_TIMESTAMP` document description

2021-06-09 Thread Tony Wei
Hi Expert,

this document [1] said `TO_TIMESTAMP` will use the session time zone to
convert date time string into a timestamp.
If I understand correctly, when I set session time zone to `Asia/Shanghai`
and query `SELECT TO_TIMESTAMP('1970-01-01 08:00:00');`,
the result should be epoch timestamp `0` (i.e. '1970-01-01 08:00:00 UTC+8').

TO_TIMESTAMP(string1[, string2])

Converts date time string *string1* with format *string2* (by default:
'-MM-dd HH:mm:ss') under the session time zone (specified by
TableConfig) to a timestamp.

Only supported in blink planner.
However, I found that result is not same as I expected. I tested it by
running the below query under the `Asia/Shanghai` timezone:

SELECT
> CAST(TO_TIMESTAMP(FROM_UNIXTIME(0)) AS BIGINT),

FROM_UNIXTIME(0),

TO_TIMESTAMP(FROM_UNIXTIME(0));


and I got the result like

  EXPR$0EXPR$1EXPR$2
> 28800   1970-01-01 08:00:00  1970-01-01T08:00


The `FROM_UNIXTIME` did convert the epoch timestamp to string format based
on session time zone, but `FROM_UNIXTIME` didn't.
Therefore, I got the `28800` when I cast timestamp into bigint. The result
actually shift 8 hours.

I found this code snippet [2] might be related to `TO_TIMESTAMP` udf, and
seems like it won't set use any timezone configuration, so maybe the
document might be wrong.

Please correct me if I misunderstood something. Thank you.

best regards,

[1]
https://ci.apache.org/projects/flink/flink-docs-release-1.12/dev/table/functions/systemFunctions.html#temporal-functions
[2]
https://github.com/apache/flink/blob/master/flink-table/flink-table-runtime-blink/src/main/java/org/apache/flink/table/runtime/functions/SqlDateTimeUtils.java#L322:L377