@@ -157,6 +157,120 @@ func (s MongoClickhouseSuite) Test_Simple_Flow_Partitioned() {
157157 RequireEnvCanceled (t , env )
158158}
159159
160+ func (s MongoClickhouseSuite ) Test_Simple_Flow_Partitioned_StringID () {
161+ t := s .T ()
162+ srcDatabase := GetTestDatabase (s .Suffix ())
163+ srcTable := "test_simple_partitioned_string_id"
164+ dstTable := "test_simple_dst_partitioned_string_id"
165+
166+ connectionGen := FlowConnectionGenerationConfig {
167+ FlowJobName : AddSuffix (s , srcTable ),
168+ TableMappings : TableMappings (s , srcTable , dstTable ),
169+ Destination : s .Peer ().Name ,
170+ }
171+ flowConnConfig := s .generateFlowConnectionConfigsDefaultEnv (connectionGen )
172+ flowConnConfig .DoInitialSnapshot = true
173+ flowConnConfig .SnapshotNumRowsPerPartition = 10
174+
175+ adminClient := s .Source ().(* MongoSource ).AdminClient ()
176+ collection := adminClient .Database (srcDatabase ).Collection (srcTable )
177+
178+ docs := make ([]any , 1000 )
179+ for i := range 1000 {
180+ docs [i ] = bson.D {
181+ {Key : "_id" , Value : fmt .Sprintf ("id-%05d" , i )},
182+ {Key : fmt .Sprintf ("init_key_%d" , i ), Value : fmt .Sprintf ("init_value_%d" , i )},
183+ }
184+ }
185+ _ , err := collection .InsertMany (t .Context (), docs )
186+ require .NoError (t , err )
187+
188+ tc := NewTemporalClient (t )
189+ env := ExecutePeerflow (t , tc , flowConnConfig )
190+
191+ EnvWaitForEqualTablesWithNames (env , s , "initial load to match" , srcTable , dstTable , "_id,doc" )
192+
193+ catalogPool , err := internal .GetCatalogConnectionPoolFromEnv (t .Context ())
194+ require .NoError (t , err )
195+ var partitionCount int
196+ require .NoError (t , catalogPool .QueryRow (t .Context (),
197+ `SELECT COUNT(*) FROM peerdb_stats.qrep_partitions WHERE parent_mirror_name = $1` ,
198+ flowConnConfig .FlowJobName ).Scan (& partitionCount ))
199+ require .Greater (t , partitionCount , 1 , "expected multiple partitions for 1000 string-id rows" )
200+
201+ SetupCDCFlowStatusQuery (t , env , flowConnConfig )
202+ cdcDocs := make ([]any , 10 )
203+ for i := range 10 {
204+ cdcDocs [i ] = bson.D {
205+ {Key : "_id" , Value : fmt .Sprintf ("cdc-%05d" , i )},
206+ {Key : fmt .Sprintf ("cdc_key_%d" , i ), Value : fmt .Sprintf ("cdc_value_%d" , i )},
207+ }
208+ }
209+ _ , err = collection .InsertMany (t .Context (), cdcDocs )
210+ require .NoError (t , err )
211+
212+ EnvWaitForEqualTablesWithNames (env , s , "cdc events to match" , srcTable , dstTable , "_id,doc" )
213+ env .Cancel (t .Context ())
214+ RequireEnvCanceled (t , env )
215+ }
216+
217+ func (s MongoClickhouseSuite ) Test_Simple_Flow_Partitioned_NumericID () {
218+ t := s .T ()
219+ srcDatabase := GetTestDatabase (s .Suffix ())
220+ srcTable := "test_simple_partitioned_numeric_id"
221+ dstTable := "test_simple_dst_partitioned_numeric_id"
222+
223+ connectionGen := FlowConnectionGenerationConfig {
224+ FlowJobName : AddSuffix (s , srcTable ),
225+ TableMappings : TableMappings (s , srcTable , dstTable ),
226+ Destination : s .Peer ().Name ,
227+ }
228+ flowConnConfig := s .generateFlowConnectionConfigsDefaultEnv (connectionGen )
229+ flowConnConfig .DoInitialSnapshot = true
230+ flowConnConfig .SnapshotNumRowsPerPartition = 10
231+
232+ adminClient := s .Source ().(* MongoSource ).AdminClient ()
233+ collection := adminClient .Database (srcDatabase ).Collection (srcTable )
234+
235+ docs := make ([]any , 1000 )
236+ for i := range 1000 {
237+ docs [i ] = bson.D {
238+ {Key : "_id" , Value : int32 (i + 1 )},
239+ {Key : fmt .Sprintf ("init_key_%d" , i ), Value : fmt .Sprintf ("init_value_%d" , i )},
240+ }
241+ }
242+ _ , err := collection .InsertMany (t .Context (), docs )
243+ require .NoError (t , err )
244+
245+ tc := NewTemporalClient (t )
246+ env := ExecutePeerflow (t , tc , flowConnConfig )
247+
248+ EnvWaitForEqualTablesWithNames (env , s , "initial load to match" , srcTable , dstTable , "_id,doc" )
249+
250+ catalogPool , err := internal .GetCatalogConnectionPoolFromEnv (t .Context ())
251+ require .NoError (t , err )
252+ var partitionCount int
253+ require .NoError (t , catalogPool .QueryRow (t .Context (),
254+ `SELECT COUNT(*) FROM peerdb_stats.qrep_partitions WHERE parent_mirror_name = $1` ,
255+ flowConnConfig .FlowJobName ).Scan (& partitionCount ))
256+ require .Greater (t , partitionCount , 1 , "expected multiple partitions for 1000 numeric-id rows" )
257+
258+ SetupCDCFlowStatusQuery (t , env , flowConnConfig )
259+ cdcDocs := make ([]any , 10 )
260+ for i := range 10 {
261+ cdcDocs [i ] = bson.D {
262+ {Key : "_id" , Value : int32 (10000 + i )},
263+ {Key : fmt .Sprintf ("cdc_key_%d" , i ), Value : fmt .Sprintf ("cdc_value_%d" , i )},
264+ }
265+ }
266+ _ , err = collection .InsertMany (t .Context (), cdcDocs )
267+ require .NoError (t , err )
268+
269+ EnvWaitForEqualTablesWithNames (env , s , "cdc events to match" , srcTable , dstTable , "_id,doc" )
270+ env .Cancel (t .Context ())
271+ RequireEnvCanceled (t , env )
272+ }
273+
160274func (s MongoClickhouseSuite ) Test_Snapshot_Collection_With_Single_Document () {
161275 t := s .T ()
162276 srcDatabase := GetTestDatabase (s .Suffix ())
0 commit comments