Package io.debezium.relational
Class TableSchema
java.lang.Object
io.debezium.relational.TableSchema
- All Implemented Interfaces:
DataCollectionSchema
Defines the Kafka Connect
Schema functionality associated with a given table definition, and which can
be used to send rows of data that match the table definition to Kafka Connect.
Given a Table definition, creating and using a TableSchema is straightforward:
Table table = ... TableSchema tableSchema = new TableSchemaBuilder().create(table);or use a subclass of
TableSchemaBuilder for the particular DBMS. Then, for each row of data:
Object[] data = ... Object key = tableSchema.keyFromColumnData(data); Struct value = tableSchema.valueFromColumnData(data); Schema keySchema = tableSchema.keySchema(); Schema valueSchema = tableSchema.valueSchema();all of which can be handed to Kafka Connect to create a new record.
When the table structure changes, simply obtain a new or updated Table definition (e.g., via an editor), rebuild the TableSchema for that Table, and use the new TableSchema instance for subsequent
records.
- Author:
- Randall Hauch
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Envelopeprivate final TableIdprivate final StructGeneratorprivate final org.apache.kafka.connect.data.Schemaprivate static final org.slf4j.Loggerprivate final StructGeneratorprivate final org.apache.kafka.connect.data.Schema -
Constructor Summary
ConstructorsConstructorDescriptionTableSchema(TableId id, org.apache.kafka.connect.data.Schema keySchema, StructGenerator keyGenerator, Envelope envelopeSchema, org.apache.kafka.connect.data.Schema valueSchema, StructGenerator valueGenerator) Create an instance with the specifiedSchemas for the keys and values, and the functions that generate the key and value for a given row of data. -
Method Summary
Modifier and TypeMethodDescriptionbooleanGet theSchemathat represents the entire value of messages for the table, i.e.inthashCode()id()org.apache.kafka.connect.data.StructkeyFromColumnData(Object[] columnData) Convert the specified row of values into a Kafka Connect key.org.apache.kafka.connect.data.SchemaGet theSchemathat represents the table's primary key.toString()org.apache.kafka.connect.data.StructvalueFromColumnData(Object[] columnData) Convert the specified row of values into a Kafka Connect value.org.apache.kafka.connect.data.SchemaGet theSchemathat represents the table's columns, excluding those that make up thekeySchema().
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
id
-
keySchema
private final org.apache.kafka.connect.data.Schema keySchema -
envelopeSchema
-
valueSchema
private final org.apache.kafka.connect.data.Schema valueSchema -
keyGenerator
-
valueGenerator
-
-
Constructor Details
-
TableSchema
public TableSchema(TableId id, org.apache.kafka.connect.data.Schema keySchema, StructGenerator keyGenerator, Envelope envelopeSchema, org.apache.kafka.connect.data.Schema valueSchema, StructGenerator valueGenerator) Create an instance with the specifiedSchemas for the keys and values, and the functions that generate the key and value for a given row of data.- Parameters:
id- the id of the table corresponding to this schemakeySchema- the schema for the primary key; may be nullkeyGenerator- the function that converts a row into a single key object for Kafka Connect; may not be null but may return nullsvalueSchema- the schema for the values; may be nullvalueGenerator- the function that converts a row into a single value object for Kafka Connect; may not be null but may return nulls
-
-
Method Details
-
id
- Specified by:
idin interfaceDataCollectionSchema
-
valueSchema
public org.apache.kafka.connect.data.Schema valueSchema()Get theSchemathat represents the table's columns, excluding those that make up thekeySchema().- Returns:
- the Schema describing the columns in the table; never null
-
keySchema
public org.apache.kafka.connect.data.Schema keySchema()Get theSchemathat represents the table's primary key.- Specified by:
keySchemain interfaceDataCollectionSchema- Returns:
- the Schema describing the column's that make up the primary key; null if there is no primary key
-
getEnvelopeSchema
Get theSchemathat represents the entire value of messages for the table, i.e. including before/after state and source info.- Specified by:
getEnvelopeSchemain interfaceDataCollectionSchema- Returns:
- the table's envelope schema
-
keyFromColumnData
Convert the specified row of values into a Kafka Connect key. The row is expected to conform to the structured defined by the table.- Parameters:
columnData- the column values for the table- Returns:
- the key, or null if the
columnData
-
valueFromColumnData
Convert the specified row of values into a Kafka Connect value. The row is expected to conform to the structured defined by the table.- Parameters:
columnData- the column values for the table- Returns:
- the value, or null if the
columnData
-
hashCode
public int hashCode() -
equals
-
toString
-