-
Notifications
You must be signed in to change notification settings - Fork 998
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kafka debezium json supports automatic discovery of primary keys
- Loading branch information
1 parent
f70f9d0
commit 0944bbe
Showing
14 changed files
with
388 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ain/java/org/apache/paimon/flink/action/cdc/kafka/KafkaKeyValueDeserializationSchema.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.paimon.flink.action.cdc.kafka; | ||
|
||
import org.apache.paimon.flink.action.cdc.format.debezium.DebeziumSchemaUtils; | ||
import org.apache.paimon.utils.Pair; | ||
|
||
import org.apache.flink.api.common.typeinfo.TypeInformation; | ||
import org.apache.flink.connector.kafka.source.reader.deserializer.KafkaRecordDeserializationSchema; | ||
import org.apache.flink.util.Collector; | ||
import org.apache.flink.util.Preconditions; | ||
import org.apache.kafka.clients.consumer.ConsumerRecord; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
/** Deserialization for kafka key and value. */ | ||
public class KafkaKeyValueDeserializationSchema | ||
implements KafkaRecordDeserializationSchema<String> { | ||
|
||
private String charset; | ||
private String format; | ||
|
||
public KafkaKeyValueDeserializationSchema(String format) { | ||
this(StandardCharsets.UTF_8.name(), format); | ||
} | ||
|
||
public KafkaKeyValueDeserializationSchema(String charset, String format) { | ||
this.charset = Preconditions.checkNotNull(charset); | ||
this.format = format; | ||
} | ||
|
||
@Override | ||
public void deserialize(ConsumerRecord<byte[], byte[]> record, Collector<String> collector) | ||
throws IOException { | ||
String value = new String(record.value(), Charset.forName(charset)); | ||
String key = | ||
record.key() != null ? new String(record.key(), Charset.forName(charset)) : null; | ||
collector.collect(DebeziumSchemaUtils.rewriteValue(Pair.of(key, value), format)); | ||
} | ||
|
||
@Override | ||
public TypeInformation<String> getProducedType() { | ||
return TypeInformation.of(String.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.