FLINK SQL中时间戳怎么处理处理

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

FLINK SQL中时间戳怎么处理处理

吴志勇
如题:
我向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表中应该怎么处理成时间格式呢?
  - name: bookpojo
    type: source-table
    connector:
      property-version: 1
      type: kafka
      version: "universal"
      topic: pojosource
      startup-mode: earliest-offset
      properties:
        zookeeper.connect: localhost:2181
        bootstrap.servers: localhost:9092
        group.id: testGroup
    format:
      property-version: 1
      type: json
      schema: "ROW<id INT, type STRING, price INT, timestamp TIMESTAMP>"
    schema:
      - name: id
        data-type: INT
      - name: type
        data-type: STRING
      - name: price
        data-type: INT
      - name: timestamp
        data-type: TIMESTAMP(3)

上述配置,好像有问题。

我在官网中找到这样一句说明:
字符串和时间类型:时间类型必须根据Java SQL时间格式进行格式化,并以毫秒为单位。例如: 2018-01-01日期,20:43:59时间和2018-01-01 20:43:59.999时间戳。
时间一定得是字符串类型且带毫秒吗?

谢谢。

Reply | Threaded
Open this post in threaded view
|

Re: FLINK SQL中时间戳怎么处理处理

Marta Paes Moreira
Hi, 吴志勇.

Please use the user-zh mailing list (in CC) to get support in Chinese.

Thanks!

Marta

On Mon, Mar 23, 2020 at 8:35 AM 吴志勇 <[hidden email]> 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表中应该怎么处理成时间格式呢?
  - name: bookpojo
    type: source-table
    connector:
      property-version: 1
      type: kafka
      version: "universal"
      topic: pojosource
      startup-mode: earliest-offset
      properties:
        zookeeper.connect: localhost:2181
        bootstrap.servers: localhost:9092
        group.id: testGroup
    format:
      property-version: 1
      type: json
      schema: "ROW<id INT, type STRING, price INT, timestamp TIMESTAMP>"
    schema:
      - name: id
        data-type: INT
      - name: type
        data-type: STRING
      - name: price
        data-type: INT
      - name: timestamp
        data-type: TIMESTAMP(3)

上述配置,好像有问题。

我在官网中找到这样一句说明:
字符串和时间类型:时间类型必须根据Java SQL时间格式进行格式化,并以毫秒为单位。例如: 2018-01-01日期,20:43:59时间和2018-01-01 20:43:59.999时间戳。
时间一定得是字符串类型且带毫秒吗?

谢谢。