@@ -599,6 +599,7 @@ private void testMongoDBParallelSourceWithMetadataColumns(
599599 + " database_name STRING METADATA VIRTUAL,"
600600 + " collection_name STRING METADATA VIRTUAL,"
601601 + " row_kind STRING METADATA VIRTUAL,"
602+ + " full_document STRING METADATA FROM 'full_document' VIRTUAL,"
602603 + " primary key (_id) not enforced"
603604 + ") WITH ("
604605 + " 'connector' = 'mongodb-cdc',"
@@ -653,16 +654,32 @@ private void testMongoDBParallelSourceWithMetadataColumns(
653654 TableResult tableResult =
654655 tEnv .executeSql (
655656 "select database_name, collection_name, row_kind, "
656- + "cid, name, address, phone_number from customers" );
657+ + "cid, name, address, phone_number, full_document from customers" );
657658 CloseableIterator <Row > iterator = tableResult .collect ();
658659 JobID jobId = tableResult .getJobClient ().get ().getJobID ();
659660 List <String > expectedSnapshotData = new ArrayList <>();
660661 for (int i = 0 ; i < captureCustomerCollections .length ; i ++) {
661662 expectedSnapshotData .addAll (snapshotForSingleTable );
662663 }
663664
664- assertEqualsInAnyOrder (
665- expectedSnapshotData , fetchRows (iterator , expectedSnapshotData .size ()));
665+ List <String > rawSnapshotData = fetchRows (iterator , expectedSnapshotData .size ());
666+
667+ // Strip full_document (last column) for precise matching of other metadata columns
668+ List <String > snapshotWithoutFullDoc =
669+ rawSnapshotData .stream ()
670+ .map (MongoDBFullChangelogITCase ::stripLastColumn )
671+ .collect (Collectors .toList ());
672+ assertEqualsInAnyOrder (expectedSnapshotData , snapshotWithoutFullDoc );
673+
674+ // Verify full_document is non-null and contains expected fields in snapshot records
675+ for (String row : rawSnapshotData ) {
676+ Assertions .assertThat (row )
677+ .as ("Snapshot full_document should contain 'cid'" )
678+ .contains ("\" cid\" " );
679+ Assertions .assertThat (row )
680+ .as ("Snapshot full_document should contain 'name'" )
681+ .contains ("\" name\" " );
682+ }
666683
667684 // second step: check the change stream data
668685 for (String collectionName : captureCustomerCollections ) {
@@ -693,11 +710,50 @@ private void testMongoDBParallelSourceWithMetadataColumns(
693710 for (int i = 0 ; i < captureCustomerCollections .length ; i ++) {
694711 expectedChangeStreamData .addAll (changeEventsForSingleTable );
695712 }
696- List <String > actualChangeStreamData = fetchRows (iterator , expectedChangeStreamData .size ());
697- assertEqualsInAnyOrder (expectedChangeStreamData , actualChangeStreamData );
713+ List <String > rawChangeStreamData = fetchRows (iterator , expectedChangeStreamData .size ());
714+
715+ // Strip full_document for precise matching of other metadata columns
716+ List <String > changeStreamWithoutFullDoc =
717+ rawChangeStreamData .stream ()
718+ .map (MongoDBFullChangelogITCase ::stripLastColumn )
719+ .collect (Collectors .toList ());
720+ assertEqualsInAnyOrder (expectedChangeStreamData , changeStreamWithoutFullDoc );
721+
722+ // Verify full_document in change stream: non-null for +I/+U, null for -D
723+ for (String row : rawChangeStreamData ) {
724+ if (row .startsWith ("+I" ) || row .startsWith ("+U" )) {
725+ Assertions .assertThat (row )
726+ .as ("Change stream full_document should contain 'name'" )
727+ .contains ("\" name\" " );
728+ }
729+ if (row .startsWith ("-D" )) {
730+ Assertions .assertThat (row )
731+ .as ("Delete event full_document should be null" )
732+ .endsWith (", null]" );
733+ }
734+ }
735+
698736 tableResult .getJobClient ().get ().cancel ().get ();
699737 }
700738
739+ /**
740+ * Strip the last column (full_document) from a Row.toString() formatted string. Row format:
741+ * "+I[col1, col2, ..., colN, full_document_json]" or "+I[col1, col2, ..., colN, null]".
742+ */
743+ private static String stripLastColumn (String row ) {
744+ // Find the last ", " before the full_document column value
745+ // The full_document is a JSON string starting with {" or null
746+ int lastJsonStart = row .lastIndexOf (", {\" " );
747+ if (lastJsonStart > 0 ) {
748+ return row .substring (0 , lastJsonStart ) + "]" ;
749+ }
750+ int lastNullStart = row .lastIndexOf (", null]" );
751+ if (lastNullStart > 0 ) {
752+ return row .substring (0 , lastNullStart ) + "]" ;
753+ }
754+ return row ;
755+ }
756+
701757 private void testMongoDBParallelSource (
702758 MongoDBTestUtils .FailoverType failoverType ,
703759 MongoDBTestUtils .FailoverPhase failoverPhase ,
0 commit comments