Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

DBZ-7956 Guard column lookup with failure if not found #82

Merged
merged 2 commits into from
Jun 21, 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 @@ -672,9 +672,6 @@ protected String columnQueryBindingFromField(String fieldName, TableDescriptor t
final FieldDescriptor field = record.getFields().get(fieldName);
final String columnName = resolveColumnName(field);
final ColumnDescriptor column = table.getColumnByName(columnName);
if (column == null) {
throw new DebeziumException("Failed to find column " + columnName + " in table " + table.getId().getTableName());
}

final Object value;
if (record.getNonKeyFieldNames().contains(fieldName)) {
Expand Down Expand Up @@ -766,7 +763,7 @@ protected String getQualifiedTableName(TableId tableId) {

private String columnNameEqualsBinding(String fieldName, TableDescriptor table, SinkRecordDescriptor record) {
final FieldDescriptor field = record.getFields().get(fieldName);
final String columnName = columnNamingStrategy.resolveColumnName(field.getColumnName());
final String columnName = resolveColumnName(field);
final ColumnDescriptor column = table.getColumnByName(columnName);
return toIdentifier(columnName) + "=" + field.getQueryBinding(column, record.getAfterStruct());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
import java.util.Map;
import java.util.stream.Collectors;

import io.debezium.DebeziumException;
import io.debezium.annotation.Immutable;
import io.debezium.connector.jdbc.JdbcSinkConnectorConfig;

/**
* Describes a relational table.
Expand Down Expand Up @@ -53,7 +55,16 @@ public Collection<ColumnDescriptor> getColumns() {
}

public ColumnDescriptor getColumnByName(String columnName) {
return columns.get(columnName);
final ColumnDescriptor column = columns.get(columnName);
if (column == null) {
throw new DebeziumException(String.format(
"Failed to find column '%s' in table '%s'. " +
"If you have not enabled '%s', this could be related to column/field case differences.",
columnName,
id.getTableName(),
JdbcSinkConnectorConfig.QUOTE_IDENTIFIERS));
}
return column;
}

public boolean hasColumn(String columnName) {
Expand Down