use of io.debezium.relational.mapping.ColumnMappers in project debezium by debezium.
the class TableSchemaBuilder method createValueGenerator.
/**
* Creates the function that produces a Kafka Connect value object for a row of data.
*
* @param schema the Kafka Connect schema for the value; may be null if there is no known schema, in which case the generator
* will be null
* @param tableId the table identifier; may not be null
* @param columns the column definitions for the table that defines the row; may not be null
* @param filter the filter that specifies whether columns in the table should be included; may be null if all columns
* are to be included
* @param mappers the mapping functions for columns; may be null if none of the columns are to be mapped to different values
* @return the value-generating function, or null if there is no value schema
*/
protected Function<Object[], Struct> createValueGenerator(Schema schema, TableId tableId, List<Column> columns, Predicate<ColumnId> filter, ColumnMappers mappers) {
if (schema != null) {
int[] recordIndexes = indexesForColumns(columns);
Field[] fields = fieldsForColumns(schema, columns);
int numFields = recordIndexes.length;
ValueConverter[] converters = convertersForColumns(schema, tableId, columns, filter, mappers);
return (row) -> {
Struct result = new Struct(schema);
for (int i = 0; i != numFields; ++i) {
Object value = row[recordIndexes[i]];
ValueConverter converter = converters[i];
if (converter != null) {
try {
value = converter.convert(value);
result.put(fields[i], value);
} catch (DataException | IllegalArgumentException e) {
Column col = columns.get(i);
LOGGER.error("Failed to properly convert data value for '{}.{}' of type {} for row {}:", tableId, col.name(), col.typeName(), row, e);
} catch (final Exception e) {
Column col = columns.get(i);
LOGGER.error("Failed to properly convert data value for '{}.{}' of type {} for row {}:", tableId, col.name(), col.typeName(), row, e);
}
}
}
return result;
};
}
return null;
}
Aggregations