Changing Dest Table Name for Multiple Tables in JDBC Sink

428 views
Skip to first unread message

Alexandre Costa e Silva (Galactros)

unread,
Oct 17, 2023, 3:44:56 PM10/17/23
to debezium
I'm configuring a jdbc sink debezium connector and in the topic configuration I'm configuring 3 tables. By default, the JDBC sink debezium creates the table in the target database based on the name of the table's topic.
I would like to change this behavior by having other options for creating the table name in the destination database.

Ex:
topics=test.Db.Table_1,test.Db.Table_2,test.Db.Table_3
Table names in target=Table_1,Table_2,Table_3

or

Table names in target=Orders,Sales,Products

Is there any way to do something this way?

Chris Cranford

unread,
Oct 17, 2023, 7:55:55 PM10/17/23
to debe...@googlegroups.com
Hi Alexandre -

There are a few ways you can influence this behavior.

The Debezium JDBC sink connector allows you to provide your own TableNamingStrategy implementation using the table.naming.strategy configuration option.  This property specifies the fully qualified class that should be used to do this mapping, allowing you full control of how you want to remap the incoming events.  The following is a quick example:

class MySpecialTableNamingStrategy extends DefaultTableNamingStrategy {
  @Override
  public String resolveTableName(JdbcSinkConnectorConfig config, SinkRecord record) {
    if (record.topic().equals("test.Db.Table_1") {
      return "Table_1";
    }   
    return super.resolveTableName(config, record);
  }
}

Now looking at this and thinking about your use case, I do think there may be a useful reason to have a "configure(HashMap<String,Object>)" method on this class so that the raw configuration for the connector is passed allowing custom implementations to be fully configurable via the connector's JSON similar to how you would do so for things like transformations, schema history and offset backing store handlers.

The other alternative would be to write your own Transformation (SMT) and utilize that as a part of your sink pipeline to remap the incoming SinkRecord's topic from A to B depending on your needs.

Hope that helps.

Thanks,
Chris

PS - I've added a follow-up to improve the strategy usage in https://issues.redhat.com/browse/DBZ-7051
--
You received this message because you are subscribed to the Google Groups "debezium" group.
To unsubscribe from this group and stop receiving emails from it, send an email to debezium+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/debezium/237bdb09-5161-46ac-b1af-e633cf99a3den%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages