Package io.debezium.relational
Class TableSchema
- java.lang.Object
-
- io.debezium.relational.TableSchema
-
- All Implemented Interfaces:
DataCollectionSchema
@Immutable public class TableSchema extends Object implements DataCollectionSchema
Defines the Kafka ConnectSchema
functionality associated with a giventable 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 aTableSchema
is straightforward:Table table = ... TableSchema tableSchema = new TableSchemaBuilder().create(table);
or use a subclass ofTableSchemaBuilder
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 aneditor
), rebuild theTableSchema
for thatTable
, and use the newTableSchema
instance for subsequent records.- Author:
- Randall Hauch
- See Also:
TableSchemaBuilder
-
-
Field Summary
Fields Modifier and Type Field Description private Envelope
envelopeSchema
private TableId
id
private StructGenerator
keyGenerator
private org.apache.kafka.connect.data.Schema
keySchema
private static org.slf4j.Logger
LOGGER
private StructGenerator
valueGenerator
private org.apache.kafka.connect.data.Schema
valueSchema
-
Constructor Summary
Constructors Constructor Description 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object obj)
Envelope
getEnvelopeSchema()
Get theSchema
that represents the entire value of messages for the table, i.e.int
hashCode()
TableId
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
keySchema()
Get theSchema
that represents the table's primary key.String
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
valueSchema()
Get theSchema
that represents the table's columns, excluding those that make up thekeySchema()
.
-
-
-
Field Detail
-
LOGGER
private static final org.slf4j.Logger LOGGER
-
id
private final TableId id
-
keySchema
private final org.apache.kafka.connect.data.Schema keySchema
-
envelopeSchema
private final Envelope envelopeSchema
-
valueSchema
private final org.apache.kafka.connect.data.Schema valueSchema
-
keyGenerator
private final StructGenerator keyGenerator
-
valueGenerator
private final StructGenerator valueGenerator
-
-
Constructor Detail
-
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 Detail
-
id
public TableId 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
public Envelope 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
public org.apache.kafka.connect.data.Struct keyFromColumnData(Object[] columnData)
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
public org.apache.kafka.connect.data.Struct valueFromColumnData(Object[] columnData)
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
-
-