Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public List<RichCdcMultiplexRecord> extractRecords() {

@Override
protected void setRoot(CdcSourceRecord record) {
// Store current record for metadata access. Assign the field directly instead of calling
// super.setRoot, because DebeziumJsonRecordParser#setRoot also parses the Debezium value
// schema, which carries no field information for BSON documents.
this.currentRecord = record;
root = (JsonNode) record.getValue();
if (root.has(FIELD_SCHEMA)) {
root = root.get(FIELD_PAYLOAD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@

package org.apache.paimon.flink.action.cdc.format.debezium;

import org.apache.paimon.flink.action.cdc.CdcMetadataConverter;
import org.apache.paimon.flink.action.cdc.CdcSourceRecord;
import org.apache.paimon.flink.action.cdc.TypeMapping;
import org.apache.paimon.flink.action.cdc.format.DataFormat;
import org.apache.paimon.flink.action.cdc.kafka.KafkaMetadataConverter;
import org.apache.paimon.flink.action.cdc.watermark.MessageQueueCdcTimestampExtractor;
import org.apache.paimon.flink.sink.cdc.CdcRecord;
import org.apache.paimon.flink.sink.cdc.CdcSchema;
import org.apache.paimon.flink.sink.cdc.RichCdcMultiplexRecord;
import org.apache.paimon.schema.Schema;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.RowKind;
import org.apache.paimon.utils.JsonSerdeUtil;
import org.apache.paimon.utils.StringUtils;
Expand All @@ -51,6 +54,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/** Test for DebeziumBsonRecordParser. */
public class DebeziumBsonRecordParserTest {
Expand Down Expand Up @@ -228,6 +232,38 @@ public void extractDeleteRecord() throws Exception {
}
}

@Test
public void extractRecordWithMetadataColumns() throws Exception {
DebeziumBsonRecordParser parser =
new DebeziumBsonRecordParser(TypeMapping.defaultMapping(), Collections.emptyList());
parser.withMetadataConverters(
new CdcMetadataConverter[] {
new KafkaMetadataConverter.TopicConverter(),
new KafkaMetadataConverter.OffsetConverter()
});

Assertions.assertFalse(insertList.isEmpty());
for (CdcSourceRecord cdcRecord : insertList) {
List<RichCdcMultiplexRecord> records = new ArrayList<>();
parser.flatMap(cdcRecord, new ListCollector<>(records));
Assertions.assertEquals(1, records.size());

Map<String, String> expected = new HashMap<>(beforeEvent);
expected.put("topic", "topic");
expected.put("offset", "0");

CdcRecord result = records.get(0).toRichCdcRecord().toCdcRecord();
Assertions.assertEquals(RowKind.INSERT, result.kind());
Assertions.assertEquals(expected, result.data());

List<String> fieldNames =
records.get(0).buildSchema().fields().stream()
.map(DataField::name)
.collect(Collectors.toList());
Assertions.assertTrue(fieldNames.containsAll(Arrays.asList("topic", "offset")));
}
}

@Test
public void bsonConvertJsonTest() throws Exception {
DebeziumBsonRecordParser parser =
Expand Down
Loading