|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.seatunnel.connectors.cdc.debezium; |
| 19 | + |
| 20 | +import org.apache.kafka.connect.errors.ConnectException; |
| 21 | + |
| 22 | +import io.debezium.util.SchemaNameAdjuster; |
| 23 | +import lombok.extern.slf4j.Slf4j; |
| 24 | + |
| 25 | +@Slf4j |
| 26 | +public class DebeziumSchemaNameAdjuster { |
| 27 | + private static final SchemaNameAdjuster.ReplacementOccurred HANDLER = |
| 28 | + (original, replacement, conflictsWith) -> { |
| 29 | + if (conflictsWith != null) { |
| 30 | + String msg = |
| 31 | + "The Kafka Connect schema name '" |
| 32 | + + original |
| 33 | + + "' is not a valid Avro schema name and its replacement '" |
| 34 | + + replacement |
| 35 | + + "' conflicts with another different schema '" |
| 36 | + + conflictsWith |
| 37 | + + "'"; |
| 38 | + log.error(msg); |
| 39 | + throw new ConnectException(msg); |
| 40 | + } else { |
| 41 | + log.warn( |
| 42 | + "The Kafka Connect schema name '{}' is not a valid Avro schema name, so replacing with '{}'", |
| 43 | + original, |
| 44 | + replacement); |
| 45 | + } |
| 46 | + }; |
| 47 | + |
| 48 | + private static final SchemaNameAdjuster.ReplacementFunction REPLACE_CHAR_HANDLER = |
| 49 | + invalid -> { |
| 50 | + // Support for Chinese characters |
| 51 | + if (Character.isIdeographic(invalid)) { |
| 52 | + return String.valueOf(invalid); |
| 53 | + } |
| 54 | + return "_"; |
| 55 | + }; |
| 56 | + |
| 57 | + public static SchemaNameAdjuster create() { |
| 58 | + return (original) -> |
| 59 | + SchemaNameAdjuster.validFullname( |
| 60 | + original, REPLACE_CHAR_HANDLER, HANDLER.firstTimeOnly()); |
| 61 | + } |
| 62 | +} |
0 commit comments