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
Modifier and TypeFieldDescriptionprivate final Envelope
private final TableId
private final StructGenerator
private final org.apache.kafka.connect.data.Schema
private static final org.slf4j.Logger
private final StructGenerator
private final org.apache.kafka.connect.data.Schema
-
Constructor Summary
ConstructorDescriptionTableSchema
(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 specifiedSchema
s for the keys and values, and the functions that generate the key and value for a given row of data. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Get theSchema
that represents the entire value of messages for the table, i.e.int
hashCode()
id()
org.apache.kafka.connect.data.Struct
keyFromColumnData
(Object[] columnData) Convert the specified row of values into a Kafka Connect key.org.apache.kafka.connect.data.Schema
Get theSchema
that represents the table's primary key.toString()
org.apache.kafka.connect.data.Struct
valueFromColumnData
(Object[] columnData) Convert the specified row of values into a Kafka Connect value.org.apache.kafka.connect.data.Schema
Get theSchema
that 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 specifiedSchema
s 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:
id
in interfaceDataCollectionSchema
-
valueSchema
public org.apache.kafka.connect.data.Schema valueSchema()Get theSchema
that 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 theSchema
that represents the table's primary key.- Specified by:
keySchema
in interfaceDataCollectionSchema
- Returns:
- the Schema describing the column's that make up the primary key; null if there is no primary key
-
getEnvelopeSchema
Get theSchema
that represents the entire value of messages for the table, i.e. including before/after state and source info.- Specified by:
getEnvelopeSchema
in 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
-