This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 7ac3f0887 [flink][bug] Fix TIMESTAMP cast error in MySQL CDC (#1014)
7ac3f0887 is described below

commit 7ac3f088765fdaeb4ae4d80b87ef405f0f23cfd0
Author: yuzelin <[email protected]>
AuthorDate: Tue Apr 25 13:57:16 2023 +0800

    [flink][bug] Fix TIMESTAMP cast error in MySQL CDC (#1014)
---
 .../flink/action/cdc/mysql/MySqlDebeziumJsonEventParser.java     | 9 +++------
 .../flink/action/cdc/mysql/MySqlSyncTableActionITCase.java       | 6 ++++--
 .../paimon-flink-common/src/test/resources/mysql/setup.sql       | 5 +++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/mysql/MySqlDebeziumJsonEventParser.java
 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/mysql/MySqlDebeziumJsonEventParser.java
index 2d6bfa72e..173917fc7 100644
--- 
a/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/mysql/MySqlDebeziumJsonEventParser.java
+++ 
b/paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/mysql/MySqlDebeziumJsonEventParser.java
@@ -271,12 +271,9 @@ public class MySqlDebeziumJsonEventParser implements 
EventParser<String> {
                     // https://dev.mysql.com/doc/refman/8.0/en/datetime.html 
for standard, and
                     // RowDataDebeziumDeserializeSchema#convertToTimestamp in 
flink-cdc-connector
                     // for implementation
-                    newValue =
-                            Instant.parse(oldValue)
-                                    .atZone(serverTimeZone)
-                                    .toLocalDateTime()
-                                    .toString()
-                                    .replace('T', ' ');
+                    LocalDateTime localDateTime =
+                            
Instant.parse(oldValue).atZone(serverTimeZone).toLocalDateTime();
+                    newValue = 
DateTimeUtils.formatLocalDateTime(localDateTime, 6);
                 } else if ("io.debezium.time.MicroTime".equals(className)) {
                     long microseconds = Long.parseLong(oldValue);
                     long microsecondsPerSecond = 1_000_000;
diff --git 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlSyncTableActionITCase.java
 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlSyncTableActionITCase.java
index f4f1b1105..969d64a79 100644
--- 
a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlSyncTableActionITCase.java
+++ 
b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/action/cdc/mysql/MySqlSyncTableActionITCase.java
@@ -427,6 +427,7 @@ public class MySqlSyncTableActionITCase extends 
MySqlActionITCaseBase {
                             DataTypes.TIMESTAMP(0), // _datetime_p
                             DataTypes.TIMESTAMP(2), // _datetime_p2
                             DataTypes.TIMESTAMP(6), // _timestamp
+                            DataTypes.TIMESTAMP(0), // _timestamp0
                             DataTypes.CHAR(10), // _char
                             DataTypes.VARCHAR(20), // _varchar
                             DataTypes.STRING(), // _tinytext
@@ -494,6 +495,7 @@ public class MySqlSyncTableActionITCase extends 
MySqlActionITCaseBase {
                             "_datetime_p",
                             "_datetime_p2",
                             "_timestamp",
+                            "_timestamp0",
                             "_char",
                             "_varchar",
                             "_tinytext",
@@ -536,7 +538,7 @@ public class MySqlSyncTableActionITCase extends 
MySqlActionITCaseBase {
                                 // we store 2023-03-23T15:00:10.123456 in 
UTC-8 system timezone
                                 // and query this timestamp in UTC-5 MySQL 
server timezone
                                 // so the display value should increase by 3 
hour
-                                + "2023-03-23T18:00:10.123456, "
+                                + "2023-03-23T18:00:10.123456, 
2023-03-23T03:10, "
                                 + "Paimon, Apache Paimon, Apache Paimon MySQL 
TINYTEXT Test Data, Apache Paimon MySQL Test Data, Apache Paimon MySQL 
MEDIUMTEXT Test Data, Apache Paimon MySQL Long Test Data, "
                                 + "[98, 121, 116, 101, 115, 0, 0, 0, 0, 0], "
                                 + "[109, 111, 114, 101, 32, 98, 121, 116, 101, 
115], "
@@ -566,7 +568,7 @@ public class MySqlSyncTableActionITCase extends 
MySqlActionITCaseBase {
                                 + "NULL, "
                                 + "NULL, NULL, NULL, "
                                 + "NULL, NULL, "
-                                + "NULL, "
+                                + "NULL, NULL, "
                                 + "NULL, NULL, NULL, NULL, NULL, NULL, "
                                 + "NULL, NULL, NULL, NULL, NULL, NULL, "
                                 + "NULL, "
diff --git 
a/paimon-flink/paimon-flink-common/src/test/resources/mysql/setup.sql 
b/paimon-flink/paimon-flink-common/src/test/resources/mysql/setup.sql
index 8812e7f38..16876ebf7 100644
--- a/paimon-flink/paimon-flink-common/src/test/resources/mysql/setup.sql
+++ b/paimon-flink/paimon-flink-common/src/test/resources/mysql/setup.sql
@@ -115,6 +115,7 @@ CREATE TABLE all_types_table (
     _datetime_p2 DATETIME(2),
     -- TIMESTAMP
     _timestamp TIMESTAMP(6) DEFAULT NULL,
+    _timestamp0 TIMESTAMP,
     -- string
     _char CHAR(10),
     _varchar VARCHAR(20),
@@ -173,7 +174,7 @@ INSERT INTO all_types_table VALUES (
     -- DATETIME precision test
     '2023-03-24 14:30', '2023-03-24 14:30:05.12',
     -- TIMESTAMP
-    '2023-03-23 15:00:10.123456',
+    '2023-03-23 15:00:10.123456', '2023-03-23 00:10',
     -- string
     'Paimon', 'Apache Paimon','Apache Paimon MySQL TINYTEXT Test Data', 
'Apache Paimon MySQL Test Data','Apache Paimon MySQL MEDIUMTEXT Test 
Data','Apache Paimon MySQL Long Test Data',
     -- BINARY
@@ -203,7 +204,7 @@ INSERT INTO all_types_table VALUES (
     NULL,
     NULL, NULL, NULL,
     NULL, NULL,
-    NULL,
+    NULL, NULL,
     NULL, NULL, NULL, NULL,NULL, NULL,
     NULL, NULL, NULL, NULL,NULL, NULL,
     NULL,

Reply via email to