@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 Function<String,String> |
schemaNameValidator |
private ValueConverterProvider |
valueConverterProvider |
| Constructor and Description |
|---|
TableSchemaBuilder(ValueConverterProvider valueConverterProvider,
Function<String,String> schemaNameValidator)
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(ResultSet resultSet,
String name)
Create a
TableSchema from the given JDBC ResultSet. |
TableSchema |
create(String schemaPrefix,
Table table)
Create a
TableSchema from the given table definition. |
TableSchema |
create(String schemaPrefix,
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 static final org.slf4j.Logger LOGGER
private final ValueConverterProvider valueConverterProvider
public TableSchemaBuilder(ValueConverterProvider valueConverterProvider, Function<String,String> schemaNameValidator)
valueConverterProvider - the provider for obtaining ValueConverters and SchemaBuilders; may not be
nullschemaNameValidator - the validation function for schema names; may not be nullpublic TableSchema create(ResultSet resultSet, String name) throws SQLException
TableSchema from the given JDBC ResultSet. The resulting TableSchema will have no primary key,
and its TableSchema.valueSchema() will contain fields for each column in the result set.resultSet - the result set for a query; may not be nullname - the name of the value schema; may not be nullSQLException - if an error occurs while using the result set's metadatapublic TableSchema create(String schemaPrefix, Table table)
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
prefixtable - the table definition; may not be nullpublic TableSchema create(String schemaPrefix, 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
prefixtable - 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 valuesprotected 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 valuesprotected 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 © 2017 JBoss by Red Hat. All rights reserved.