Alibaba-HZY commented on code in PR #1239: URL: https://github.com/apache/incubator-paimon/pull/1239#discussion_r1206320120
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/KafkaSchema.java: ########## @@ -0,0 +1,153 @@ +/* + * 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.mysql.MySqlTypeUtils; +import org.apache.paimon.types.DataType; + +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.node.ArrayNode; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.streaming.connectors.kafka.table.KafkaConnectorOptions; +import org.apache.kafka.clients.consumer.ConsumerConfig; +import org.apache.kafka.clients.consumer.ConsumerRecord; +import org.apache.kafka.clients.consumer.ConsumerRecords; +import org.apache.kafka.clients.consumer.KafkaConsumer; +import org.apache.kafka.common.serialization.StringDeserializer; + +import java.time.Duration; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.UUID; + +/** Utility class to load canal kafka schema. */ +public class KafkaSchema { + + private static final ObjectMapper objectMapper = new ObjectMapper(); + + private String databaseName; + private String tableName; + private final Map<String, DataType> fields; + private final List<String> primaryKeys; + private static final int RETRY = Integer.MAX_VALUE; + + public KafkaSchema(Configuration kafkaConfig, String topic) throws Exception { + + fields = new LinkedHashMap<>(); + primaryKeys = new ArrayList<>(); + KafkaConsumer<String, String> consumer = getKafkaConsumer(kafkaConfig); + + consumer.subscribe(Collections.singletonList(topic)); + + int retry = 0; + boolean success = false; + while (!success) { + ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100)); + for (ConsumerRecord<String, String> record : records) { Review Comment: it needs multiple cycles,now it may be wrong when first record is ddl event, so parseCanalJson need return bool -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
