Skip to content

Commit 7073bb7

Browse files
committed
mysql: map 00 day/month to 01
1 parent 0068e66 commit 7073bb7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

flow/connectors/mysql/qvalue_convert.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func QValueFromMysqlFieldValue(qkind types.QValueKind, mytype byte, fv mysql.Fie
316316
if strings.HasPrefix(unsafeString, "0000-00-00") {
317317
return types.QValueTimestamp{Val: time.Unix(0, 0)}, nil
318318
}
319-
val, err := time.Parse("2006-01-02 15:04:05.999999", unsafeString)
319+
val, err := time.Parse("2006-01-02 15:04:05.999999", strings.ReplaceAll(unsafeString, "-00", "-01"))
320320
if err != nil {
321321
return nil, err
322322
}
@@ -334,7 +334,7 @@ func QValueFromMysqlFieldValue(qkind types.QValueKind, mytype byte, fv mysql.Fie
334334
if unsafeString == "0000-00-00" {
335335
return types.QValueDate{Val: time.Unix(0, 0)}, nil
336336
}
337-
val, err := time.Parse(time.DateOnly, unsafeString)
337+
val, err := time.Parse(time.DateOnly, strings.ReplaceAll(unsafeString, "-00", "-01"))
338338
if err != nil {
339339
return nil, err
340340
}
@@ -471,7 +471,7 @@ func QValueFromMysqlRowEvent(
471471
if val == "0000-00-00" {
472472
return types.QValueDate{Val: time.Unix(0, 0)}, nil
473473
}
474-
val, err := time.Parse(time.DateOnly, val)
474+
val, err := time.Parse(time.DateOnly, strings.ReplaceAll(val, "-00", "-01"))
475475
if err != nil {
476476
return nil, err
477477
}
@@ -487,7 +487,7 @@ func QValueFromMysqlRowEvent(
487487
if strings.HasPrefix(val, "0000-00-00") {
488488
return types.QValueTimestamp{Val: time.Unix(0, 0)}, nil
489489
}
490-
tm, err := time.Parse("2006-01-02 15:04:05.999999", val)
490+
tm, err := time.Parse("2006-01-02 15:04:05.999999", strings.ReplaceAll(val, "-00", "-01"))
491491
if err != nil {
492492
return nil, err
493493
}

flow/e2e/clickhouse/mysql_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s ClickHouseSuite) Test_MySQL_Time() {
8585
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",d,dt,tm,t) VALUES
8686
('init','1935-01-01','1953-02-02 12:01:02','1973-02-02 13:01:02.123','14:21.654321'),
8787
('init','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','00:00'),
88-
('init','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','-800:0:1')`,
88+
('init','2000-01-00','2000-00-01 00:00:00','2000-00-00 00:00:00.000','-800:0:1')`,
8989
quotedSrcFullName)))
9090

9191
connectionGen := e2e.FlowConnectionGenerationConfig{
@@ -105,7 +105,7 @@ func (s ClickHouseSuite) Test_MySQL_Time() {
105105
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",d,dt,tm,t) VALUES
106106
('cdc','1935-01-01','1953-02-02 12:01:02','1973-02-02 13:01:02.123','14:21.654321'),
107107
('cdc','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','00:00'),
108-
('cdc','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','-800:0:1')`,
108+
('cdc','2000-01-00','2000-00-01 00:00:00','2000-00-00 00:00:00.000','-800:0:1')`,
109109
quotedSrcFullName)))
110110

111111
e2e.EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,\"key\",d,dt,tm,t")

0 commit comments

Comments
 (0)