Uploaded image for project: 'Debezium'
  1. Debezium
  2. DBZ-6641

Schema name changed with Custom topic naming strategy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 2.4.0.Beta1
    • 2.3.0.Final
    • core-library
    • None
    • False
    • None
    • False

      In order to make your issue reports as actionable as possible, please provide the following information, depending on the issue type.

      Bug report

      For bug reports, provide this information, please:

      What Debezium connector do you use and what version?

      debezium-postgres-connector - v1.6.2.Final

      What is the connector configuration?

      N/A

      What is the captured database version and mode of depoyment?

      (E.g. on-premises, with a specific cloud provider, etc.)

      N/A

      What behaviour do you expect?

      Expected no change in schema names of Envelop, Key and Value records.

      Default behavior :

      Envelope - <prefix>.<schema>.<table>
      Key - <prefix>.<schema>.<table>.Key
      Value - <prefix>.<schema>.<table>.Value

      Topic Name - <prefix>.<schema>.<table>

      where <prefix> is from the database.server.name and topic.prefix in 1.6.2 and 2.x respectively{{ }}

      Schema names incase of custom topic naming selector:

      Topic Name - <custom-topic-name>

      Envelope - <prefix>.<schema>.<table>
      Key - <prefix>.<schema>.<table>.Key
      Value - <prefix>.<schema>.<table>.Value

      The above schema names must be same in 2.x with custom naming strategy as well. Schema prefix in 1.9.7 (same as in 1.6.2) is https://github.com/debezium/debezium/blob/v1.9.7.Final/debezium-core/src/main/java/io/debezium/relational/TableSchemaBuilder.java#L132

      What behaviour do you see?

      Schema names incase of custom topic naming strategy in DBZ 2.x:

      Topic Name - <custom-topic-name>

      Envelope - <custom-topic-name>
      Key - <custom-topic-name>.Key
      Value - <custom-topic-name>.Value

      because TopicNamingStrategy#dataChangeTopic returns topic name.

      Schema prefix in 2.X is https://github.com/debezium/debezium/blob/main/debezium-core/src/main/java/io/debezium/relational/TableSchemaBuilder.java#L125

      {{}}

      Do you see the same behaviour using the latest relesead Debezium version?

      (Ideally, also verify with latest Alpha/Beta/CR version)

      Yes

      Do you have the connector logs, ideally from start till finish?

      (You might be asked later to provide DEBUG/TRACE level log)

      N/A

      How to reproduce the issue using our tutorial deployment?

      N/A

      Feature request or enhancement

      For feature requests or enhancements, provide this information, please:

      Which use case/requirement will be addressed by the proposed feature?

      <Your answer>

      Implementation ideas (optional)

      This can be implemented by having separate method to determine the schema prefix. 

      public interface TopicNamingStrategy<I extends DataCollectionId> {
       
      // .. current methods
      
       default String recordSchemaPrefix(I id) {
         // to support current behavior  
         return dataChangeTopic(id);
       }
       
      
      } 
      
      
      public class TableSchemaBuilder {
      
        public TableSchema create(TopicNamingStrategy topicNamingStrategy, Table table, ColumnNameFilter filter, ColumnMappers mappers, KeyMapper keysMapper) {
         
         ...
      
         final String schemaNamePrefix = topicNamingStrategy.recordSchemaPrefix(tableId);
         final String envelopeSchemaPrefix = topicNamingStrategy.dataChangeTopic(tableId);
         final String envelopSchemaName = Envelope.schemaName(envelopeSchemaPrefix);
      
         ...
        
        }
      
      }
      
      
      public class CustomTopicNamingStrategy extends SchemaTopicNamingStrategy {
      
        private String topicName = null;
         
         public CustomTopicNamingStrategy(Properties props) {
           super(props);
           String topicName = props.getProperty(FieldConstants.CUSTOM_TOPIC_NAME);
           if (!Strings.isNullOrBlank(topicName)) {
              this.topicName = props.getProperty(FieldConstants.CUSTOM_TOPIC_NAME);
           }
         }
      
      
         @Override
         public String dataChangeTopic(DataCollectionId id) {
          if (this.topicName != null) {
              return topicName;
          }
      
          return super.dataChangeTopic(id);
         }
      
         public String recordSchemaPrefix(DataCollectionId id) {
          // return AbstractTopicNamingStrategy's dataChangeTopic implementation which returns <prefix>.<schema>.<table>
           return super.dataChangeTopic(id);
         }
      }

            Unassigned Unassigned
            dasarianil1505 Anil Dasari
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: