FROM_UNIXTIME 使用的是本地时区, (可以看,org.apache.flink.table.runtime.functions.
SqlDateTimeUtils#fromUnixtime的实现)
可以指定时区,StreamTableEnvironment.getConfig().setLocalTimeZone()

Joker <[email protected]> 于2020年9月24日周四 下午1:54写道:

> 不好意思,插入个问题。ts AS TO_TIMESTAMP(FROM_UNIXTIME(create_time / 1000,
> 'yyyy-MM-dd HH:mm:ss')) ,我按此方式生成事件时间列,发现watermark一直比北京时间多8小时,比如create_time
> 为1600926591666,ts计算出来是2020/9/24
> 13:49:51没问题,但在WebUI上发现提取的watermark为2020/9/24 21:49:51
>
>
> | |
> Joker
> |
> |
> [email protected]
> |
> 签名由网易邮箱大师定制
>
>
> 在2020年09月24日 13:40,Jark Wu<[email protected]> 写道:
> Flink 的 TO_TIMESTAMP 函数用的是 Java SimpleDateFormat 来解析时间格式的,所以可以看下
> SimpleDateFormat 的 javadoc。
> 你可以试下 to_timestamp('2020-09-23T20:58:24+08:00',
> 'yyyy-MM-dd''T''HH:mm:ssXXX') 来解析你的数据。
>
> Best,
> Jark
>
> On Wed, 23 Sep 2020 at 21:08, chenxuying <[email protected]> wrote:
>
> flinksql 版本是1.11.2
> source接收到字段是字符串类型的时间
> CREATE TABLE sourceTable (
> `time` STRING
> ) WITH(
> ...
> );
>
>
> sink如下
> CREATE TABLE sinktable (
> `time1` STRING,
> `time` TIMESTAMP(3)
> ) WITH (
> 'connector' = 'print'
> );
>
>
> insert语句,不知道怎么正确修改TO_TIMESTAMP默认的格式
> insert into sinktable select
> `time`,TO_TIMESTAMP(`time`,'yyyy-MM-ddTHH:mm:ss+08:00') from sourceTable
>
>
> 报错说是format错误
> Caused by: java.lang.IllegalArgumentException: Unknown pattern letter: T
> at
>
> java.time.format.DateTimeFormatterBuilder.parsePattern(DateTimeFormatterBuilder.java:1663)
> at
>
> java.time.format.DateTimeFormatterBuilder.appendPattern(DateTimeFormatterBuilder.java:1572)
> at java.time.format.DateTimeFormatter.ofPattern(DateTimeFormatter.java:534)
>


-- 
**************************************
 tivanli
**************************************

回复