@ThreadSafe @Immutable public class TableSchemaBuilder extends Object
TableSchema instances for Table definitions.
This builder is responsible for mapping table columns to fields in Kafka Connect Schemas,
and this is necessarily dependent upon the database's supported types. Although mappings are defined for standard types,
this class may need to be subclassed for each DBMS to add support for DBMS-specific types by overriding any of the
"add*Field" methods.
See the Java SE Mapping SQL
and Java Types for details about how JDBC types map to Java value types.
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
LOGGER |
private SchemaNameAdjuster |
schemaNameAdjuster |
private org.apache.kafka.connect.data.Schema |
sourceInfoSchema |
private ValueConverterProvider |
valueConverterProvider |
| Constructor and Description |
|---|
TableSchemaBuilder(ValueConverterProvider valueConverterProvider,
SchemaNameAdjuster schemaNameAdjuster,
org.apache.kafka.connect.data.Schema sourceInfoSchema)
Create a new instance of the builder.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
addField(org.apache.kafka.connect.data.SchemaBuilder builder,
Column column,
ColumnMapper mapper)
Add to the supplied
SchemaBuilder a field for the column with the given information. |
protected ValueConverter[] |
convertersForColumns(org.apache.kafka.connect.data.Schema schema,
TableId tableId,
List<Column> columns,
Predicate<ColumnId> filter,
ColumnMappers mappers)
Obtain the array of converters for each column in a row.
|
TableSchema |
create(String schemaPrefix,
String envelopSchemaName,
Table table,
Predicate<ColumnId> filter,
ColumnMappers mappers)
Create a
TableSchema from the given table definition. |
protected Function<Object[],Object> |
createKeyGenerator(org.apache.kafka.connect.data.Schema schema,
TableId columnSetName,
List<Column> columns)
Creates the function that produces a Kafka Connect key object for a row of data.
|
protected ValueConverter |
createValueConverterFor(Column column,
org.apache.kafka.connect.data.Field fieldDefn)
Create a
ValueConverter that can be used to convert row values for the given column into the Kafka Connect value
object described by the field definition. |
protected Function<Object[],org.apache.kafka.connect.data.Struct> |
createValueGenerator(org.apache.kafka.connect.data.Schema schema,
TableId tableId,
List<Column> columns,
Predicate<ColumnId> filter,
ColumnMappers mappers)
Creates the function that produces a Kafka Connect value object for a row of data.
|
protected org.apache.kafka.connect.data.Field[] |
fieldsForColumns(org.apache.kafka.connect.data.Schema schema,
List<Column> columns) |
protected int[] |
indexesForColumns(List<Column> columns) |
private String |
tableSchemaName(TableId tableId)
Returns the type schema name for the given table.
|
private ValueConverter |
wrapInMappingConverterIfNeeded(ColumnMappers mappers,
TableId tableId,
Column column,
ValueConverter converter) |
private static final org.slf4j.Logger LOGGER
private final SchemaNameAdjuster schemaNameAdjuster
private final ValueConverterProvider valueConverterProvider
private final org.apache.kafka.connect.data.Schema sourceInfoSchema
public TableSchemaBuilder(ValueConverterProvider valueConverterProvider, SchemaNameAdjuster schemaNameAdjuster, org.apache.kafka.connect.data.Schema sourceInfoSchema)
valueConverterProvider - the provider for obtaining ValueConverters and SchemaBuilders; may not be
nullschemaNameAdjuster - the adjuster for schema names; may not be nullpublic TableSchema create(String schemaPrefix, String envelopSchemaName, Table table, Predicate<ColumnId> filter, ColumnMappers mappers)
TableSchema from the given table definition. The resulting TableSchema will have a
key schema that contains all of the columns that make up the table's primary key,
and a value schema that contains only those columns that are not in the table's primary
key.
This is equivalent to calling create(table,false).
schemaPrefix - the prefix added to the table identifier to construct the schema names; may be null if there is no
prefixenvelopSchemaName - the name of the schema of the built table's envelopetable - the table definition; may not be nullfilter - the filter that specifies whether columns in the table should be included; may be null if all columns
are to be includedmappers - the mapping functions for columns; may be null if none of the columns are to be mapped to different valuesprivate String tableSchemaName(TableId tableId)
protected Function<Object[],Object> createKeyGenerator(org.apache.kafka.connect.data.Schema schema, TableId columnSetName, List<Column> columns)
schema - the Kafka Connect schema for the key; may be null if there is no known schema, in which case the generator
will be nullcolumnSetName - the name for the set of columns, used in error messages; may not be nullcolumns - the column definitions for the table that defines the row; may not be nullprotected Function<Object[],org.apache.kafka.connect.data.Struct> createValueGenerator(org.apache.kafka.connect.data.Schema schema, TableId tableId, List<Column> columns, Predicate<ColumnId> filter, ColumnMappers mappers)
schema - the Kafka Connect schema for the value; may be null if there is no known schema, in which case the generator
will be nulltableId - the table identifier; may not be nullcolumns - the column definitions for the table that defines the row; may not be nullfilter - the filter that specifies whether columns in the table should be included; may be null if all columns
are to be includedmappers - the mapping functions for columns; may be null if none of the columns are to be mapped to different valuesprotected org.apache.kafka.connect.data.Field[] fieldsForColumns(org.apache.kafka.connect.data.Schema schema,
List<Column> columns)
protected ValueConverter[] convertersForColumns(org.apache.kafka.connect.data.Schema schema, TableId tableId, List<Column> columns, Predicate<ColumnId> filter, ColumnMappers mappers)
schema - the schema; may not be nulltableId - the identifier of the table that contains the columnscolumns - the columns in the row; may not be nullfilter - the filter that specifies whether columns in the table should be included; may be null if all columns
are to be includedmappers - the mapping functions for columns; may be null if none of the columns are to be mapped to different valuesprivate ValueConverter wrapInMappingConverterIfNeeded(ColumnMappers mappers, TableId tableId, Column column, ValueConverter converter)
protected void addField(org.apache.kafka.connect.data.SchemaBuilder builder,
Column column,
ColumnMapper mapper)
SchemaBuilder a field for the column with the given information.builder - the schema builder; never nullcolumn - the column definitionmapper - the mapping function for the column; may be null if the columns is not to be mapped to different valuesprotected ValueConverter createValueConverterFor(Column column, org.apache.kafka.connect.data.Field fieldDefn)
ValueConverter that can be used to convert row values for the given column into the Kafka Connect value
object described by the field definition. This uses the supplied ValueConverterProvider object.column - the column describing the input values; never nullfieldDefn - the definition for the field in a Kafka Connect Schema describing the output of the function;
never nullCopyright © 2019 JBoss by Red Hat. All rights reserved.