DBZ-7599 Write toast placeholder instead of null for binary types when "hex" mode configured

This commit is contained in:
Nick Golubev 2024-03-04 22:31:04 +03:00 committed by Jiri Pechanec
parent edaea2f3fc
commit 69efa7e218
4 changed files with 34 additions and 0 deletions

View File

@ -593,3 +593,4 @@ Clifford Cheefoon
Fr0z3Nn
Xianming Zhou
Akula
Nick Golubev

View File

@ -1162,6 +1162,9 @@ protected Object convertBinaryToBase64UrlSafe(Column column, Field fieldDefn, Ob
@Override
protected Object convertBinaryToHex(Column column, Field fieldDefn, Object data) {
if (data == UnchangedToastedReplicationMessageColumn.UNCHANGED_TOAST_VALUE) {
return unchangedToastedPlaceholder.getToastPlaceholderString();
}
return super.convertBinaryToHex(column, fieldDefn, (data instanceof PGobject) ? ((PGobject) data).getValue() : data);
}

View File

@ -23,6 +23,7 @@
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalTime;
import java.time.OffsetDateTime;
@ -103,6 +104,7 @@
import io.debezium.time.MicroTimestamp;
import io.debezium.time.ZonedTime;
import io.debezium.time.ZonedTimestamp;
import io.debezium.util.HexConverter;
import io.debezium.util.Stopwatch;
import io.debezium.util.Testing;
@ -1801,6 +1803,33 @@ final var record = consumer.remove();
.isEqualTo(SchemaBuilder.array(Schema.OPTIONAL_BYTES_SCHEMA).optional().build());
}
@Test
public void shouldHandleToastedByteaColumnInHexMode() throws Exception {
TestHelper.execute(
"DROP TABLE IF EXISTS test_toast_table;",
"CREATE TABLE test_toast_table (id SERIAL PRIMARY KEY);");
startConnector(config -> config.with(CommonConnectorConfig.BINARY_HANDLING_MODE, BinaryHandlingMode.HEX), false);
final String toastedValue = RandomStringUtils.randomNumeric(10000);
String statement = "ALTER TABLE test_toast_table ADD COLUMN not_toast integer;"
+ "ALTER TABLE test_toast_table ADD COLUMN bytea_ bytea;"
+ "ALTER TABLE test_toast_table ALTER COLUMN bytea_ SET STORAGE EXTENDED;"
+ "INSERT INTO test_toast_table (not_toast, bytea_) values (10, '" + toastedValue + "'::bytea);";
consumer = testConsumer(1);
executeAndWait(statement);
// after record should contain the toasted value
assertValueField(consumer.remove(), "after/bytea_", HexConverter.convertToHexString(toastedValue.getBytes(StandardCharsets.UTF_8)));
statement = "UPDATE test_toast_table SET not_toast = 2;";
consumer.expects(1);
executeAndWait(statement);
// after update of toasted value record should contain the placeholder
assertValueField(consumer.remove(), "after/bytea_", DecoderDifferences.mandatoryToastedValuePlaceholder());
}
@Test
@FixFor("DBZ-5936")
public void shouldHandleToastedIntegerArrayColumn() throws Exception {

View File

@ -259,3 +259,4 @@ nrkeli,Emil Lindström
akulapid,Akula
ArthurLR,Arthur Le Ray
Lars M Johansson,Lars M. Johansson
nivolg,Nick Golubev