Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DBZ-8235 Add invalid value logger to VitessValueConverter #209

Merged
merged 1 commit into from
Sep 13, 2024
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 @@ -38,6 +38,7 @@
public class VitessValueConverter extends JdbcValueConverters {

private static final Logger LOGGER = LoggerFactory.getLogger(VitessValueConverter.class);
private static final Logger INVALID_VALUE_LOGGER = LoggerFactory.getLogger(VitessValueConverter.class.getName() + ".invalid_value");
private static final BigDecimal BIGINT_MAX_VALUE = new BigDecimal("18446744073709551615");
private static final BigDecimal BIGINT_CORRECTION = BIGINT_MAX_VALUE.add(BigDecimal.ONE);

Expand Down Expand Up @@ -361,7 +362,7 @@ public static LocalDate stringToLocalDate(String dateString) {
final int day = Integer.parseInt(matcher.group(3));

if (year == 0 || month == 0 || day == 0) {
LOGGER.warn("Invalid value '{}' stored in column converted to empty value", dateString);
INVALID_VALUE_LOGGER.warn("Invalid value '{}' stored in column converted to empty value", dateString);
return null;
}
return LocalDate.of(year, month, day);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.junit.Test;

import io.debezium.connector.vitess.connection.VStreamOutputMessageDecoder;
import io.debezium.junit.logging.LogInterceptor;
import io.debezium.relational.Column;
import io.debezium.relational.Table;
import io.debezium.relational.ValueConverter;
Expand Down Expand Up @@ -256,4 +257,11 @@ public void shouldConvertStringToTimestamp() {
assertThat(VitessValueConverter.stringToTimestamp("2000-01-01 00:00:00.123456")).isEqualTo(
Timestamp.valueOf(LocalDate.of(2000, 1, 1).atStartOfDay().withNano(123456 * 1000)));
}

@Test
public void shouldConvertInvalidValueToLocalData() {
final LogInterceptor logInterceptor = new LogInterceptor(VitessValueConverter.class.getName() + ".invalid_value");
assertThat(VitessValueConverter.stringToLocalDate("0000-00-00")).isNull();
assertThat(logInterceptor.containsMessage("Invalid value")).isTrue();
}
}