-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathclickhouse_mysql_test.go
More file actions
1941 lines (1664 loc) · 75 KB
/
Copy pathclickhouse_mysql_test.go
File metadata and controls
1941 lines (1664 loc) · 75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package e2e
import (
"context"
"encoding/hex"
"fmt"
"math"
"strconv"
"strings"
"testing"
"time"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
"github.com/PeerDB-io/peerdb/flow/connectors"
connclickhouse "github.com/PeerDB-io/peerdb/flow/connectors/clickhouse"
"github.com/PeerDB-io/peerdb/flow/generated/protos"
"github.com/PeerDB-io/peerdb/flow/internal"
"github.com/PeerDB-io/peerdb/flow/pkg/clickhouse"
mysql_validation "github.com/PeerDB-io/peerdb/flow/pkg/mysql"
"github.com/PeerDB-io/peerdb/flow/shared"
"github.com/PeerDB-io/peerdb/flow/shared/types"
)
func mysqlEnumUsesOrdinals(source *MySqlSource) bool {
return source.Config.Flavor == protos.MySqlFlavor_MYSQL_MYSQL &&
source.Config.ReplicationMechanism == protos.MySqlReplicationMechanism_MYSQL_FILEPOS
}
func (s ClickHouseSuite) Test_UnsignedMySQL() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_unsigned"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_unsigned"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`CREATE TABLE %s (
id serial primary key,
i8 tinyint, u8 tinyint unsigned,
i16 smallint, u16 smallint unsigned,
i24 mediumint zerofill, u24 mediumint unsigned,
i32 int, u32 int unsigned zerofill,
i64 bigint, u64 bigint unsigned,
d decimal(7, 6), b boolean
)`, srcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`insert into %s
(i8,u8,i16,u16,i24,u24,i32,u32,i64,u64,d,b)
values (-1, 200, -2, 40000, -3, 10000000, -4, 3000000000, %d, %d, 3.141592,true)
`, srcFullName, int64(math.MinInt64), uint64(math.MaxUint64))))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: srcFullName,
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,i8,u8,i16,u16,i24,u24,i32,u32,i64,u64,d,b")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`insert into %s
(i8,u8,i16,u16,i24,u24,i32,u32,i64,u64,d,b)
values (-1, 200, -2, 40000, -3, 10000000, -4, 3000000000, %d, %d, 3.141592,false)
`, srcFullName, int64(math.MinInt64), uint64(math.MaxUint64))))
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,i8,u8,i16,u16,i24,u24,i32,u32,i64,u64,d,b")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Time() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_datetime"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_datetime_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
"key" TEXT NOT NULL,
d DATE NOT NULL,
dt DATETIME NOT NULL,
tm TIMESTAMP(6) NOT NULL,
t TIME NOT NULL,
y YEAR NOT NULL
)
`, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",d,dt,tm,t,y) VALUES
('init','1935-01-01','1953-02-02 12:01:02','1973-02-02 13:01:02.123','14:21.654321',1935),
('init','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','00:00',0),
('init','2000-01-00','2000-00-01 00:00:00','2000-01-01 00:00:00.000','-800:0:1',2155)`,
quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,\"key\",d,dt,tm,t,y")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",d,dt,tm,t,y) VALUES
('cdc','1935-01-01','1953-02-02 12:01:02','1973-02-02 13:01:02.123','14:21.654321',1935),
('cdc','0000-00-00','0000-00-00 00:00:00','0000-00-00 00:00:00.000','00:00',0),
('cdc','2000-01-00','2000-00-01 00:00:00','2000-01-01 00:00:00.000','-800:0:1',2155)`,
quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,\"key\",d,dt,tm,t,y")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Bit() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_bit"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_bit_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
"key" TEXT NOT NULL,
b1 bit(1) NOT NULL,
b20 bit(20) NOT NULL
)
`, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",b1,b20) VALUES
('init',b'1',b'11100011100011100011'), ('init',b'0',b'00011100011100011100')`, quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,\"key\",b1,b20")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",b1,b20) VALUES
('cdc','1','11100011100011100011'), ('cdc','0','00011100011100011100')`, quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,\"key\",b1,b20")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Blobs() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_blobs"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_blobs_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
k TEXT NOT NULL,
tb tinyblob NOT NULL,
mb mediumblob NOT NULL,
lb longblob NOT NULL,
bi binary(6) NOT NULL,
vb varbinary(100) NOT NULL,
tt tinytext NOT NULL,
mt mediumtext NOT NULL,
lt longtext NOT NULL,
ch char(4) NOT NULL,
vc varchar(100) NOT NULL,
js json NOT NULL
)
`, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s (k,tb,mb,lb,bi,vb,tt,mt,lt,ch,vc,js) VALUES
('init','tinyblob','mediumblob','longblob','binary','varbinary',
'tinytext','mediumtext','longtext','char','varchar','{"a":2}')`, quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,k,tb,mb,lb,vb,bi,tt,mt,lt,ch,vc,js")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s (k,tb,mb,lb,bi,vb,tt,mt,lt,ch,vc,js) VALUES
('cdc','tinyblob','mediumblob','longblob','binary','varbinary',
'tinytext','mediumtext','longtext','char','varchar','{"a":2}')`, quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,k,tb,mb,lb,bi,vb,tt,mt,lt,ch,vc,js")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_TransactionPayloadCompression() {
mySource, ok := s.source.(*MySqlSource)
if !ok {
s.t.Skip("only applies to mysql")
}
if mySource.Config.Flavor == protos.MySqlFlavor_MYSQL_MARIA {
s.t.Skip("binlog_transaction_compression is not supported by MariaDB")
}
cmp, err := mySource.CompareServerVersion(s.t.Context(), mysql_validation.MySQLMinVersionForBinlogTransactionCompression)
require.NoError(s.t, err)
if cmp < 0 {
s.t.Skip("only applies to mysql versions with binlog_transaction_compression")
}
srcTableName := "test_txn_payload"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_txn_payload_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id BIGINT PRIMARY KEY,
val TEXT NOT NULL
)
`, srcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
// Compress this session's transactions so the upcoming DML lands in the binlog as a single
// TRANSACTION_PAYLOAD_EVENT, exercising the compressed-payload decode path in CDC.
require.NoError(s.t, s.source.Exec(s.t.Context(), "SET SESSION binlog_transaction_compression = ON"))
// Capture the binlog position, then write a large, highly compressible transaction as a single
// multi-row INSERT so MySQL compresses it (compressed < uncompressed) into one payload event.
posBefore, err := mySource.GetMasterPos(s.t.Context())
require.NoError(s.t, err)
const rowCount = 200
rowVal := strings.Repeat("peerdb-compressible-", 100) // ~2KB highly repetitive per row
var insert strings.Builder
fmt.Fprintf(&insert, "INSERT INTO %s (id, val) VALUES ", srcFullName)
for i := 1; i <= rowCount; i++ {
if i > 1 {
insert.WriteByte(',')
}
fmt.Fprintf(&insert, "(%d, '%s')", i, rowVal)
}
require.NoError(s.t, s.source.Exec(s.t.Context(), insert.String()))
findPayloadEndPos := func(ctx context.Context, from mysql.Position) (bool, uint32, error) {
rs, err := mySource.Execute(ctx, fmt.Sprintf("SHOW BINLOG EVENTS IN '%s' FROM %d", from.Name, from.Pos))
if err != nil {
return false, 0, err
}
for i := range rs.Values {
// SHOW BINLOG EVENTS columns: Log_name, Pos, Event_type, Server_id, End_log_pos, Info
eventType, _ := rs.GetString(i, 2)
if strings.Contains(strings.ToLower(eventType), "payload") {
pos, _ := rs.GetInt(i, 4)
return true, uint32(pos), nil
}
}
return false, 0, nil
}
hasPayload, payloadEndPos, err := findPayloadEndPos(s.t.Context(), posBefore)
require.NoError(s.t, err)
require.True(s.t, hasPayload, "expected a TRANSACTION_PAYLOAD_EVENT in the binlog")
// for GTID "SHOW BINLOG EVENTS" returns really complex format and it's different
// across versions/flavors.
// Therefore, we just get the latest GTID from a server instead of reading it from a binglog.
gtidAfter, err := mySource.GetMasterGTIDSet(s.t.Context())
require.NoError(s.t, err)
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,val")
// Assert the payload transaction was checkpointed
pool, err := catalogTestAccessPool()
require.NoError(s.t, err)
var lastText string
require.NoError(s.t, pool.QueryRow(s.t.Context(),
"SELECT last_text FROM metadata_last_sync_state WHERE job_name = $1",
flowConnConfig.FlowJobName,
).Scan(&lastText))
if rest, isFilePos := strings.CutPrefix(lastText, "!f:"); isFilePos {
comma := strings.LastIndexByte(rest, ',')
require.NotEqual(s.t, -1, comma, "malformed file/pos offset %q", lastText)
storedPos, parseErr := strconv.ParseUint(rest[comma+1:], 16, 32)
require.NoError(s.t, parseErr)
require.GreaterOrEqual(s.t, uint32(storedPos), payloadEndPos,
"checkpoint did not advance past the TRANSACTION_PAYLOAD_EVENT")
} else {
storedSet, parseErr := mysql.ParseGTIDSet(mySource.Flavor(), lastText)
require.NoError(s.t, parseErr)
require.True(s.t, storedSet.Contain(gtidAfter),
"checkpoint GTID set %s does not cover the committed payload transaction %s", storedSet, gtidAfter)
}
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
// Test_MySQL_Binary_Trailing_Zeros reproduces trailing-0x00 truncation of fixed-length
// BINARY(N) columns over CDC.
//
// MySQL right-pads BINARY(N) to N bytes with 0x00. Internally this is represented
// as a binary array of length M=N-number_of_trailing(0x00). When reading from binlog these
// values need to be adapted back to N bytes based on the column type.
//
// See https://github.com/shyiko/mysql-binlog-connector-java/issues/169#issuecomment-301864569
// for a similar problem in a different project.
func (s ClickHouseSuite) Test_MySQL_Binary_Trailing_Zeros() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_binary_padding"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_binary_padding_dst"
type binaryCase struct {
id int
label string
beforeSnapshot bool
// BINARY(16) covers the common short metadata path with a 1-byte row length.
b16InsertHex string
b16WantHex string
// BINARY(255) covers the upper edge of the same metadata path without switching
// to MySQL's 2-byte row length encoding for fixed strings longer than 255 bytes.
// MySQL does not allow BINARY(N) with N > 255.
b255InsertHex string
b255WantHex string
}
cases := []binaryCase{
// SELECT path: correct today, included to prove snapshot and CDC agree.
{
id: 1,
label: "snapshot_trailing_zero",
beforeSnapshot: true,
b16InsertHex: strings.Repeat("11", 15) + "00",
b16WantHex: strings.Repeat("11", 15) + "00",
b255InsertHex: strings.Repeat("11", 254) + "00",
b255WantHex: strings.Repeat("11", 254) + "00",
},
// CDC path: MySQL packs these shorter than their declared BINARY(N) length.
{
id: 2,
label: "cdc_trailing_zero",
beforeSnapshot: false,
b16InsertHex: "21" + strings.Repeat("11", 14) + "00",
b16WantHex: "21" + strings.Repeat("11", 14) + "00",
b255InsertHex: "21" + strings.Repeat("11", 253) + "00",
b255WantHex: "21" + strings.Repeat("11", 253) + "00",
},
{
id: 3,
label: "cdc_multiple_trailing_zeros",
beforeSnapshot: false,
b16InsertHex: "22" + strings.Repeat("11", 11) + strings.Repeat("00", 4),
b16WantHex: "22" + strings.Repeat("11", 11) + strings.Repeat("00", 4),
b255InsertHex: "22" + strings.Repeat("11", 250) + strings.Repeat("00", 4),
b255WantHex: "22" + strings.Repeat("11", 250) + strings.Repeat("00", 4),
},
{
id: 4,
label: "cdc_all_zero",
beforeSnapshot: false,
b16InsertHex: strings.Repeat("00", 16),
b16WantHex: strings.Repeat("00", 16),
b255InsertHex: strings.Repeat("00", 255),
b255WantHex: strings.Repeat("00", 255),
},
{
id: 5,
label: "cdc_short_insert",
beforeSnapshot: false,
b16InsertHex: "41",
b16WantHex: "41" + strings.Repeat("00", 15),
b255InsertHex: "42",
b255WantHex: "42" + strings.Repeat("00", 254),
},
// Controls: interior zero bytes and non-zero tails should be preserved without extra padding.
{
id: 6,
label: "cdc_interior_zero_nonzero_tail",
beforeSnapshot: false,
b16InsertHex: "FF00112233445566778899AABBCCDDEE",
b16WantHex: "FF00112233445566778899AABBCCDDEE",
b255InsertHex: "FF00" + strings.Repeat("7F", 252) + "EE",
b255WantHex: "FF00" + strings.Repeat("7F", 252) + "EE",
},
}
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id INT PRIMARY KEY,
label TEXT NOT NULL,
b16 BINARY(16) NOT NULL,
b255 BINARY(255) NOT NULL
)
`, quotedSrcFullName)))
var snapshotCases []binaryCase
var cdcCases []binaryCase
for _, tc := range cases {
if tc.beforeSnapshot {
snapshotCases = append(snapshotCases, tc)
} else {
cdcCases = append(cdcCases, tc)
}
}
snapshotValues := make([]string, 0, len(snapshotCases))
for _, tc := range snapshotCases {
snapshotValues = append(snapshotValues, fmt.Sprintf(
"(%d,'%s',UNHEX('%s'),UNHEX('%s'))",
tc.id, tc.label, tc.b16InsertHex, tc.b255InsertHex))
}
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (id,label,b16,b255) VALUES %s`, quotedSrcFullName, strings.Join(snapshotValues, ","))))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForCount(env, s, "waiting for snapshot row", dstTableName, "id,label,b16,b255", len(snapshotCases))
cdcValues := make([]string, 0, len(cdcCases))
for _, tc := range cdcCases {
cdcValues = append(cdcValues, fmt.Sprintf(
"(%d,'%s',UNHEX('%s'),UNHEX('%s'))",
tc.id, tc.label, tc.b16InsertHex, tc.b255InsertHex))
}
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (id,label,b16,b255) VALUES %s`, quotedSrcFullName, strings.Join(cdcValues, ","))))
EnvWaitForCount(env, s, "waiting for cdc rows", dstTableName, "id,label,b16,b255", len(cases))
rows, err := s.GetRows(dstTableName, "id,label,b16,b255")
require.NoError(s.t, err)
require.Len(s.t, rows.Records, len(cases), "expected all binary padding test rows")
byLabel := make(map[string]map[string][]byte, len(rows.Records))
for _, row := range rows.Records {
label, ok := row[1].Value().(string)
require.True(s.t, ok, "label should be a string")
byLabel[label] = make(map[string][]byte, 2)
for _, col := range []struct {
name string
idx int
}{
{name: "b16", idx: 2},
{name: "b255", idx: 3},
} {
switch v := row[col.idx].Value().(type) {
case string:
byLabel[label][col.name] = []byte(v)
case []byte:
byLabel[label][col.name] = v
default:
require.Failf(s.t, "unexpected type for binary column",
"label=%s column=%s type=%T", label, col.name, row[col.idx].Value())
}
}
}
for _, tc := range cases {
for _, col := range []struct {
name string
wantHex string
}{
{name: "b16", wantHex: tc.b16WantHex},
{name: "b255", wantHex: tc.b255WantHex},
} {
want, decErr := hex.DecodeString(col.wantHex)
require.NoError(s.t, decErr)
gotByCol, ok := byLabel[tc.label]
require.Truef(s.t, ok, "missing row %q in destination", tc.label)
got, ok := gotByCol[col.name]
require.Truef(s.t, ok, "missing column %q for row %q in destination", col.name, tc.label)
require.Equalf(s.t, want, got,
"%s %q: MySQL stores %d bytes (%s) but ClickHouse has %d bytes (%s)",
col.name, tc.label, len(want), col.wantHex, len(got), strings.ToUpper(hex.EncodeToString(got)))
}
}
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Enum() {
if mySource, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
} else {
cmp, err := mySource.CompareServerVersion(s.t.Context(), mysql_validation.MySQLMinVersionForBinlogRowMetadata)
require.NoError(s.t, err)
if cmp < 0 {
s.t.Skip("only applies to mysql versions with binlog_row_metadata")
}
}
srcTableName := "test_my_enum"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_my_enum_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
"key" TEXT NOT NULL,
e enum('a','b''s', 'c') NOT NULL,
s set('a','b','c') NOT NULL
)
`, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",e,s) VALUES
('init','b''s','a,b'),('init','','')`, quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,\"key\",e,s")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`INSERT INTO %s ("key",e,s) VALUES
('cdc','b''s','a,b'),('cdc','','')`, quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,\"key\",e,s")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Enum_Consistency() {
mySource, ok := s.source.(*MySqlSource)
if !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_my_enum_consistency"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_my_enum_consistency_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
status ENUM('active', 'inactive', 'pending') NOT NULL
)
`, srcFullName)))
// Insert row before snapshot
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (status) VALUES ('active')`, srcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
// Wait for snapshot row to appear in destination
EnvWaitForCount(env, s, "waiting on snapshot", dstTableName, "id,status", 1)
// Insert row via CDC — on old MySQL this comes as integer from binlog
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (status) VALUES ('active')`, srcFullName)))
// Wait for CDC row
EnvWaitForCount(env, s, "waiting on cdc", dstTableName, "id,status", 2)
// Verify both rows have the same status value (consistency between snapshot and CDC)
rows, err := s.GetRows(dstTableName, "id,status")
require.NoError(s.t, err)
require.Len(s.t, rows.Records, 2)
require.Equal(s.t, rows.Records[0][1].Value(), rows.Records[1][1].Value(),
"snapshot and CDC enum values should be consistent")
if mysqlEnumUsesOrdinals(mySource) {
require.EqualValues(s.t, 1, rows.Records[0][1].Value())
} else {
require.Equal(s.t, "active", rows.Records[0][1].Value())
}
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Enum_Consistency_Version0() {
mySource, ok := s.source.(*MySqlSource)
if !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_my_enum_consistency_v0"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_my_enum_consistency_v0_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
status ENUM('active', 'inactive', 'pending') NOT NULL
)
`, srcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (status) VALUES ('active')`, srcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
flowConnConfig.Env = map[string]string{"PEERDB_FORCE_INTERNAL_VERSION": strconv.FormatUint(uint64(shared.InternalVersion_First), 10)}
flowConnConfig.Version = shared.InternalVersion_First
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForCount(env, s, "waiting on snapshot", dstTableName, "id,status", 1)
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (status) VALUES ('active')`, srcFullName)))
EnvWaitForCount(env, s, "waiting on cdc", dstTableName, "id,status", 2)
rows, err := s.GetRows(dstTableName, "id,status")
require.NoError(s.t, err)
require.Len(s.t, rows.Records, 2)
require.EqualValues(s.t, 1, rows.Records[0][0].Value())
require.EqualValues(s.t, 2, rows.Records[1][0].Value())
require.Equal(s.t, "active", rows.Records[0][1].Value())
if mysqlEnumUsesOrdinals(mySource) {
require.Equal(s.t, "1", rows.Records[1][1].Value())
} else {
require.Equal(s.t, "active", rows.Records[1][1].Value())
}
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Charset_Consistency() {
if mySource, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
} else {
// Transcoding relies on collation metadata in TABLE_MAP, only present with binlog_row_metadata.
cmp, err := mySource.CompareServerVersion(s.t.Context(), mysql_validation.MySQLMinVersionForBinlogRowMetadata)
require.NoError(s.t, err)
if cmp < 0 {
s.t.Skip("only applies to mysql versions with binlog_row_metadata")
}
}
srcTableName := "test_my_charset"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_my_charset_dst"
// latin1 (Windows-1252) and gbk columns: their stored bytes are NOT UTF-8.
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (
id SERIAL PRIMARY KEY,
latin1_col VARCHAR(50) CHARACTER SET latin1 NOT NULL,
gbk_col VARCHAR(50) CHARACTER SET gbk NOT NULL,
latin1_enum ENUM('café', 'plain') CHARACTER SET latin1 NOT NULL,
gbk_set SET('你好', '再见') CHARACTER SET gbk NOT NULL
)
`, quotedSrcFullName)))
// Insert before snapshot. The source connection runs SET NAMES utf8mb4, so the server
// transcodes these UTF-8 literals down into the columns' latin1/gbk storage encodings.
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (latin1_col, gbk_col, latin1_enum, gbk_set) VALUES ('café', '你好', 'café', '你好,再见')`,
quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForCount(env, s, "waiting on snapshot", dstTableName, "id,latin1_col,gbk_col,latin1_enum,gbk_set", 1)
// Same values via CDC (binlog path).
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(
`INSERT INTO %s (latin1_col, gbk_col, latin1_enum, gbk_set) VALUES ('café', '你好', 'café', '你好,再见')`,
quotedSrcFullName)))
EnvWaitForCount(env, s, "waiting on cdc", dstTableName, "id,latin1_col,gbk_col,latin1_enum,gbk_set", 2)
rows, err := s.GetRows(dstTableName, "id,latin1_col,gbk_col,latin1_enum,gbk_set")
require.NoError(s.t, err)
require.Len(s.t, rows.Records, 2)
// Snapshot (row 0) and CDC (row 1) must be byte-identical and correctly decoded.
require.Equal(s.t, rows.Records[0][1].Value(), rows.Records[1][1].Value(),
"snapshot and CDC latin1 values should be consistent")
require.Equal(s.t, rows.Records[0][2].Value(), rows.Records[1][2].Value(),
"snapshot and CDC gbk values should be consistent")
require.Equal(s.t, rows.Records[0][3].Value(), rows.Records[1][3].Value(),
"snapshot and CDC latin1 enum values should be consistent")
require.Equal(s.t, rows.Records[0][4].Value(), rows.Records[1][4].Value(),
"snapshot and CDC gbk set values should be consistent")
require.Equal(s.t, "café", rows.Records[1][1].Value())
require.Equal(s.t, "你好", rows.Records[1][2].Value())
require.Equal(s.t, "café", rows.Records[1][3].Value())
require.Equal(s.t, "你好,再见", rows.Records[1][4].Value())
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Vector() {
mysource, ok := s.source.(*MySqlSource)
if !ok {
s.t.Skip("only applies to mysql")
}
var createTableSQL, initialInsertSQL, cdcInsertSQL string
switch mysource.Config.Flavor {
case protos.MySqlFlavor_MYSQL_MYSQL:
cmp, err := mysource.CompareServerVersion(s.t.Context(), "9.0.0")
require.NoError(s.t, err)
if cmp < 0 {
s.t.Skip("VECTOR type is only supported in MySQL 9.0+")
}
createTableSQL = `CREATE TABLE IF NOT EXISTS %s (id SERIAL PRIMARY KEY, val VECTOR)`
initialInsertSQL = `INSERT INTO %s (val) VALUES (to_vector('[1.1,1.0]'))`
cdcInsertSQL = `INSERT INTO %s (val) VALUES (to_vector('[2.718, 1.414]'))`
case protos.MySqlFlavor_MYSQL_MARIA:
cmp, err := mysource.CompareServerVersion(s.t.Context(), "11.7.0")
require.NoError(s.t, err)
if cmp < 0 {
s.t.Skip("VECTOR type is only supported in MariaDB 11.7+")
}
createTableSQL = `CREATE TABLE IF NOT EXISTS %s (id SERIAL PRIMARY KEY, val VECTOR(2))`
initialInsertSQL = `INSERT INTO %s (val) VALUES (Vec_FromText('[1.1,1.0]'))`
cdcInsertSQL = `INSERT INTO %s (val) VALUES (Vec_FromText('[2.718, 1.414]'))`
default:
require.FailNow(s.t, fmt.Sprintf("unsupported MySQL flavor: %s", mysource.Config.Flavor))
}
srcTableName := "test_vector"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_vector_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(createTableSQL, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(initialInsertSQL, quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,val")
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(cdcInsertSQL, quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,val")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Numbers() {
if mysource, ok := s.source.(*MySqlSource); !ok || mysource.Config.Flavor != protos.MySqlFlavor_MYSQL_MYSQL {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_float"
srcFullName := s.attachSchemaSuffix(srcTableName)
quotedSrcFullName := "\"" + strings.ReplaceAll(srcFullName, ".", "\".\"") + "\""
dstTableName := "test_float_dst"
require.NoError(s.t, s.source.Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s (id SERIAL PRIMARY KEY, num numeric, num603 numeric(60, 3), f32 float, f64 double precision, r real)
`, quotedSrcFullName)))
require.NoError(s.t, s.source.Exec(s.t.Context(),
fmt.Sprintf(`INSERT INTO %s(num,num603,f32,f64,r)VALUES(1.23,780780780.780,1.41421,2.718281828459045,6.28319)`,
quotedSrcFullName)))
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix(srcTableName),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
EnvWaitForEqualTablesWithNames(env, s, "waiting on initial", srcTableName, dstTableName, "id,num,num603,f32,f64,r")
require.NoError(s.t, s.source.Exec(s.t.Context(),
fmt.Sprintf(`INSERT INTO%s(num,num603,f32,f64,r)VALUES(1.23,780780780.780,1.41421,2.718281828459045,6.28319)`,
quotedSrcFullName)))
EnvWaitForEqualTablesWithNames(env, s, "waiting on cdc", srcTableName, dstTableName, "id,num,num603,f32,f64,r")
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Geometric_Types() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_mysql_geometric_types"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_mysql_geometric_types"
// Create a table with a geometry column that can store any geometric type
err := s.Source().Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s(
id serial PRIMARY KEY,
geometry_col GEOMETRY
)`, srcFullName))
require.NoError(s.t, err)
// Insert test data with various geometric types
err = s.Source().Exec(s.t.Context(), fmt.Sprintf(`
INSERT INTO %s (geometry_col) VALUES
(ST_GeomFromText('POINT(1 2)')),
(ST_GeomFromText('LINESTRING(1 2, 3 4)')),
(ST_GeomFromText('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))')),
(ST_GeomFromText('MULTIPOINT(1 2, 3 4)')),
(ST_GeomFromText('MULTILINESTRING((1 2, 3 4), (5 6, 7 8))')),
(ST_GeomFromText('MULTIPOLYGON(((1 1, 3 1, 3 3, 1 3, 1 1)), ((4 4, 6 4, 6 6, 4 6, 4 4)))')),
(ST_GeomFromText('GEOMETRYCOLLECTION(POINT(1 2), LINESTRING(1 2, 3 4))')),
(ST_GeomFromText('POINT(5 6)', 3857))`, srcFullName))
require.NoError(s.t, err)
connectionGen := FlowConnectionGenerationConfig{
FlowJobName: s.attachSuffix("clickhouse_test_mysql_geometric_types"),
TableNameMapping: map[string]string{srcFullName: dstTableName},
Destination: s.Peer().Name,
}
flowConnConfig := connectionGen.GenerateFlowConnectionConfigs(s)
flowConnConfig.DoInitialSnapshot = true
tc := NewTemporalClient(s.t)
env := ExecutePeerflow(s.t, tc, flowConnConfig)
SetupCDCFlowStatusQuery(s.t, env, flowConnConfig)
// Wait for initial snapshot to complete
EnvWaitForCount(env, s, "waiting for initial snapshot count", dstTableName, "id", 8)
// Insert additional rows to test CDC
err = s.Source().Exec(s.t.Context(), fmt.Sprintf(`
INSERT INTO %s (geometry_col) VALUES
(ST_GeomFromText('POINT(10 20)')),
(ST_GeomFromText('LINESTRING(10 20, 30 40)')),
(ST_GeomFromText('POLYGON((10 10, 30 10, 30 30, 10 30, 10 10))')),
(ST_GeomFromText('POINT(30 40)', 3857))`, srcFullName))
require.NoError(s.t, err)
// Wait for CDC to replicate the new rows
EnvWaitForCount(env, s, "waiting for CDC count", dstTableName, "id", 12)
// Verify that the data was correctly replicated
rows, err := s.GetRows(dstTableName, "id, geometry_col")
require.NoError(s.t, err)
require.Len(s.t, rows.Records, 12, "expected 12 rows")
// Expected WKT format values for each geometric type.
// SRID is intentionally dropped because ClickHouse doesn't support EWKT (SRID=N;WKT).
expectedValues := []string{
"POINT (1 2)",
"LINESTRING (1 2, 3 4)",
"POLYGON ((1 1, 3 1, 3 3, 1 3, 1 1))",
"MULTIPOINT ((1 2), (3 4))",
"MULTILINESTRING ((1 2, 3 4), (5 6, 7 8))",
"MULTIPOLYGON (((1 1, 3 1, 3 3, 1 3, 1 1)), ((4 4, 6 4, 6 6, 4 6, 4 4)))",
"GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (1 2, 3 4))",
"POINT (5 6)",
"POINT (10 20)",
"LINESTRING (10 20, 30 40)",
"POLYGON ((10 10, 30 10, 30 30, 10 30, 10 10))",
"POINT (30 40)",
}
for i, row := range rows.Records {
require.Len(s.t, row, 2, "expected 2 columns")
geometryVal := row[1].Value()
require.Equal(s.t, expectedValues[i], geometryVal, "geometry_col value mismatch at row %d", i+1)
}
// Clean up
env.Cancel(s.t.Context())
RequireEnvCanceled(s.t, env)
}
func (s ClickHouseSuite) Test_MySQL_Specific_Geometric_Types() {
if _, ok := s.source.(*MySqlSource); !ok {
s.t.Skip("only applies to mysql")
}
srcTableName := "test_mysql_s_geometric_types"
srcFullName := s.attachSchemaSuffix(srcTableName)
dstTableName := "test_mysql_s_geometric_types"
// Create a table with a geometry column that can store any geometric type
err := s.Source().Exec(s.t.Context(), fmt.Sprintf(`
CREATE TABLE IF NOT EXISTS %s(
id serial PRIMARY KEY,
point_col POINT,
linestring_col LINESTRING,
polygon_col POLYGON,
multipoint_col MULTIPOINT,
multilinestring_col MULTILINESTRING,
multipolygon_col MULTIPOLYGON,
geometrycollection_col GEOMETRYCOLLECTION