You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-zh@flink.apache.org by "casel.chen" <ca...@126.com> on 2022/04/21 12:44:54 UTC

flink cdc 时间格式和时区问题

我在使用flink cdc 2.2.0获取mysql数据变更, mysqlSource设置了 .serverTimeZone("Asia/Shanghai") 
发现mysql timestamp 类型的数据在mysql workbench里显示的是 "2021-06-24 16:26:47",通过JsonDebeziumDeserializationSchema解析后得到的json string串是 "2021-06-24T08:26:47Z"。继而在通过org.apache.flink.formats.json.JsonToRowDataConverters转成RowData时解析timestamp失败 (private TimestampData convertToTimestamp(JsonNode jsonNode)方法),因为当前只支持SQL和ISO_8601两种TimestampFormat,我看到 org.apache.flink.formats.common.TimeFormats 类中除了支持这两种timestamp外,还支持 RFC3339_TIMESTAMP_FORMAT。


问题:
1. 为什么RFC3339没有出现在 org.apache.flink.formats.common.TimestampFormat中呢?我在debug窗口试了用RFC3339_TIMESTAMP_FORMAT.parse(jsonNode.asText())是可以出结果的。
2. 开头设置的时区 "Asia/Shanghai" 为什么没有生效?实际返回的时间表示还是UTC时区的


附mysql服务器时区设置如下

mysql> show variables like'%time_zone';

+------------------+--------+

| Variable_name    | Value  |

+------------------+--------+

| system_time_zone | CST    |

| time_zone        | SYSTEM |

+------------------+--------+