@Immutable public class TableSchema extends Object implements DataCollectionSchema
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.
TableSchemaBuilder
Modifier and Type | Field and 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 and 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 specified
Schema s for the keys and values, and the functions that generate the
key and value for a given row of data. |
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
Envelope |
getEnvelopeSchema()
Get the
Schema 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 the
Schema 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 the
Schema that represents the table's columns, excluding those that make up the keySchema() . |
private static final org.slf4j.Logger LOGGER
private final TableId id
private final org.apache.kafka.connect.data.Schema keySchema
private final Envelope envelopeSchema
private final org.apache.kafka.connect.data.Schema valueSchema
private final StructGenerator keyGenerator
private final StructGenerator valueGenerator
public TableSchema(TableId id, org.apache.kafka.connect.data.Schema keySchema, StructGenerator keyGenerator, Envelope envelopeSchema, org.apache.kafka.connect.data.Schema valueSchema, StructGenerator valueGenerator)
Schema
s for the keys and values, and the functions that generate the
key and value for a given row of data.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 nullspublic TableId id()
id
in interface DataCollectionSchema
public org.apache.kafka.connect.data.Schema valueSchema()
Schema
that represents the table's columns, excluding those that make up the keySchema()
.public org.apache.kafka.connect.data.Schema keySchema()
Schema
that represents the table's primary key.keySchema
in interface DataCollectionSchema
public Envelope getEnvelopeSchema()
Schema
that represents the entire value of messages for the table, i.e. including before/after state
and source info.getEnvelopeSchema
in interface DataCollectionSchema
public org.apache.kafka.connect.data.Struct keyFromColumnData(Object[] columnData)
columnData
- the column values for the tablecolumnData
public org.apache.kafka.connect.data.Struct valueFromColumnData(Object[] columnData)
columnData
- the column values for the tablecolumnData
Copyright © 2020 JBoss by Red Hat. All rights reserved.