Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -18,13 +18,15 @@
package org.apache.flink.cdc.connectors.postgres.source;

import org.apache.flink.cdc.common.annotation.Internal;
import org.apache.flink.cdc.common.data.RecordData;
import org.apache.flink.cdc.common.data.binary.BinaryStringData;
import org.apache.flink.cdc.common.event.SchemaChangeEvent;
import org.apache.flink.cdc.common.event.TableId;
import org.apache.flink.cdc.connectors.postgres.table.PostgreSQLReadableMetadata;
import org.apache.flink.cdc.debezium.event.DebeziumEventDeserializationSchema;
import org.apache.flink.cdc.debezium.table.DebeziumChangelogMode;
import org.apache.flink.table.data.TimestampData;
import org.apache.flink.util.Preconditions;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.debezium.data.Envelope;
Expand Down Expand Up @@ -83,6 +85,19 @@ public PostgresEventDeserializer(
this.databaseName = databaseName;
}

@Override
protected RecordData extractBeforeDataRecord(Struct value, Schema valueSchema)
throws Exception {
Struct beforeValue = fieldStruct(value, Envelope.FieldName.BEFORE);
Preconditions.checkNotNull(
beforeValue,
"Before data is null for UPDATE/DELETE event. "
+ "This usually happens when the source table is not configured with "
+ "REPLICA IDENTITY FULL. Schema name: "
+ valueSchema.name());
return super.extractBeforeDataRecord(value, valueSchema);
}
Comment thread
BreadS00 marked this conversation as resolved.

Comment thread
BreadS00 marked this conversation as resolved.
@Override
protected List<SchemaChangeEvent> deserializeSchemaChangeRecord(SourceRecord record) {
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.flink.cdc.runtime.typeutils.BinaryRecordDataGenerator;
import org.apache.flink.cdc.runtime.typeutils.EventTypeInfo;
import org.apache.flink.util.Collector;
import org.apache.flink.util.Preconditions;

import io.debezium.data.Envelope;
import io.debezium.data.SpecialValueDecimal;
Expand Down Expand Up @@ -141,15 +142,23 @@ public TypeInformation<Event> getProducedType() {
return new EventTypeInfo();
}

private RecordData extractBeforeDataRecord(Struct value, Schema valueSchema) throws Exception {
protected RecordData extractBeforeDataRecord(Struct value, Schema valueSchema)
throws Exception {
Schema beforeSchema = fieldSchema(valueSchema, Envelope.FieldName.BEFORE);
Struct beforeValue = fieldStruct(value, Envelope.FieldName.BEFORE);
Preconditions.checkNotNull(
beforeValue,
"Before data is null for UPDATE/DELETE event. Schema name: " + valueSchema.name());
return extractDataRecord(beforeValue, beforeSchema);
}

private RecordData extractAfterDataRecord(Struct value, Schema valueSchema) throws Exception {
Schema afterSchema = fieldSchema(valueSchema, Envelope.FieldName.AFTER);
Struct afterValue = fieldStruct(value, Envelope.FieldName.AFTER);
Preconditions.checkNotNull(
afterValue,
"After data is null for CREATE/READ/UPDATE event. Schema name: "
+ valueSchema.name());
Comment thread
yuxiqian marked this conversation as resolved.
Outdated
return extractDataRecord(afterValue, afterSchema);
}

Expand Down