flink-user-zh mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zhenghua Gao <doc...@gmail.com>
Subject Re: FLINK SQL中时间戳怎么处理处理
Date Mon, 23 Mar 2020 10:22:45 GMT
你定义的Kafka source使用JsonRowDeserializationSchema 解析json字符串并将其转换为Flink
types
[1]。
目前JsonRowDeserializationSchema 仅支持 RFC 3339兼容的时间字符串 [2]。

[1]
https://github.com/apache/flink/blob/master/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/JsonRowDeserializationSchema.java#L446
[2]
https://github.com/apache/flink/blob/master/flink-formats/flink-json/src/main/java/org/apache/flink/formats/json/TimeFormats.java#L38

*Best Regards,*
*Zhenghua Gao*


On Mon, Mar 23, 2020 at 4:27 PM 吴志勇 <1154365135@qq.com> wrote:

> 如题:
> 我向kafka中输出了json格式的数据
> {"id":5,"price":40,"timestamp":1584942626828,"type":"math"}
> {"id":2,"price":70,"timestamp":1584942629638,"type":"math"}
> {"id":2,"price":70,"timestamp":1584942634951,"type":"math"}
>
> ....
> 其中timestamp字段是13位时间戳,对应的SQL表中应该怎么处理成时间格式呢?
> &nbsp;&nbsp;-&nbsp;name:&nbsp;bookpojo
> &nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;source-table
> &nbsp;&nbsp;&nbsp;&nbsp;connector:&nbsp;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property-version:&nbsp;1
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;kafka
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;version:&nbsp;"universal"
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;topic:&nbsp;pojosource
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;startup-mode:&nbsp;earliest-offset
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;properties:
>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;zookeeper.connect:&nbsp;localhost:2181
>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bootstrap.servers:&nbsp;localhost:9092
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;group.id:&nbsp;testGroup
> &nbsp;&nbsp;&nbsp;&nbsp;format:&nbsp;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;property-version:&nbsp;1
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;type:&nbsp;json
>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;schema:&nbsp;"ROW<id&nbsp;INT,&nbsp;type&nbsp;STRING,&nbsp;price&nbsp;INT,&nbsp;timestamp&nbsp;TIMESTAMP&gt;"
> &nbsp;&nbsp;&nbsp;&nbsp;schema:&nbsp;
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;id
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data-type:&nbsp;INT
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;type
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data-type:&nbsp;STRING
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;price
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data-type:&nbsp;INT
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;name:&nbsp;timestamp
>
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;data-type:&nbsp;TIMESTAMP(3)
>
>
>
>
> 上述配置,好像有问题。
>
>
> 我在官网中找到这样一句说明:
> 字符串和时间类型:不修剪值。文字"null"也可以理解。时间类型必须根据Java
> SQL时间格式进行格式化,并以毫秒为单位。例如:&nbsp;2018-01-01日期,20:43:59时间和2018-01-01
> 20:43:59.999时间戳。
> 时间一定得是字符串类型且带毫秒吗?
>
>
> 谢谢。

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message