JingsongLi commented on code in PR #1239:
URL: https://github.com/apache/incubator-paimon/pull/1239#discussion_r1206503810


##########
paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/KafkaSyncTableAction.java:
##########
@@ -0,0 +1,354 @@
+/*
+ * 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.catalog.Catalog;
+import org.apache.paimon.catalog.CatalogContext;
+import org.apache.paimon.catalog.CatalogFactory;
+import org.apache.paimon.catalog.Identifier;
+import org.apache.paimon.flink.FlinkConnectorOptions;
+import org.apache.paimon.flink.action.Action;
+import org.apache.paimon.flink.action.cdc.ComputedColumn;
+import org.apache.paimon.flink.action.cdc.kafka.canal.CanalJsonEventParser;
+import org.apache.paimon.flink.sink.cdc.EventParser;
+import org.apache.paimon.flink.sink.cdc.FlinkCdcSyncTableSinkBuilder;
+import org.apache.paimon.options.CatalogOptions;
+import org.apache.paimon.options.Options;
+import org.apache.paimon.schema.Schema;
+import org.apache.paimon.table.FileStoreTable;
+
+import org.apache.flink.api.common.eventtime.WatermarkStrategy;
+import org.apache.flink.api.java.tuple.Tuple3;
+import org.apache.flink.api.java.utils.MultipleParameterTool;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.connector.kafka.source.KafkaSource;
+import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
+import org.apache.flink.streaming.connectors.kafka.table.KafkaConnectorOptions;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import static org.apache.paimon.utils.Preconditions.checkArgument;
+
+/**
+ * An {@link Action} which synchronize one kafka topic into one Paimon table.
+ *
+ * <p>This topic must be from canal-json format.
+ *
+ * <p>You should specify Kafka source topic in {@code kafkaConfig}. See <a
+ * 
href="https://nightlies.apache.org/flink/flink-docs-release-1.16/zh/docs/connectors/table/kafka/";>document
+ * of flink-connectors</a> for detailed keys and values.
+ *
+ * <p>If the specified Paimon table does not exist, this action will 
automatically create the table.
+ * Its schema will be derived from all specified Kafka topic. If the Paimon 
table already exists,
+ * its schema will be compared against the schema of all specified Kafka topic.
+ *
+ * <p>This action supports a limited number of schema changes. Unsupported 
schema changes will be
+ * ignored. Currently supported schema changes includes:
+ *
+ * <ul>
+ *   <li>Adding columns.
+ *   <li>Altering column types. More specifically,
+ *       <ul>
+ *         <li>altering from a string type (char, varchar, text) to another 
string type with longer
+ *             length,
+ *         <li>altering from a binary type (binary, varbinary, blob) to 
another binary type with
+ *             longer length,
+ *         <li>altering from an integer type (tinyint, smallint, int, bigint) 
to another integer
+ *             type with wider range,
+ *         <li>altering from a floating-point type (float, double) to another 
floating-point type
+ *             with wider range,
+ *       </ul>
+ *       are supported. Other type changes will cause exceptions.
+ * </ul>
+ */
+public class KafkaSyncTableAction implements Action {
+
+    private final Configuration kafkaConfig;
+    private final String warehouse;
+    private final String database;
+    private final String table;
+    private final List<String> partitionKeys;
+    private final List<String> primaryKeys;
+
+    private final List<String> computedColumnArgs;
+
+    Map<String, String> catalogConfig;
+    private final Map<String, String> paimonConfig;
+
+    KafkaSyncTableAction(
+            Map<String, String> kafkaConfig,
+            String warehouse,
+            String database,
+            String table,
+            List<String> partitionKeys,
+            List<String> primaryKeys,
+            Map<String, String> catalogConfig,
+            Map<String, String> paimonConfig) {
+        this(
+                kafkaConfig,
+                warehouse,
+                database,
+                table,
+                partitionKeys,
+                primaryKeys,
+                Collections.emptyList(),
+                catalogConfig,
+                paimonConfig);
+    }
+
+    public KafkaSyncTableAction(
+            Map<String, String> kafkaConfig,
+            String warehouse,
+            String database,
+            String table,
+            List<String> partitionKeys,
+            List<String> primaryKeys,
+            List<String> computedColumnArgs,
+            Map<String, String> catalogConfig,
+            Map<String, String> paimonConfig) {
+        this.kafkaConfig = Configuration.fromMap(kafkaConfig);
+        this.warehouse = warehouse;
+        this.database = database;
+        this.table = table;
+        this.partitionKeys = partitionKeys;
+        this.primaryKeys = primaryKeys;
+        this.computedColumnArgs = computedColumnArgs;
+        this.catalogConfig = catalogConfig;
+        this.paimonConfig = paimonConfig;
+    }
+
+    public void build(StreamExecutionEnvironment env) throws Exception {
+        checkArgument(
+                kafkaConfig.contains(KafkaConnectorOptions.VALUE_FORMAT),
+                KafkaConnectorOptions.VALUE_FORMAT.key() + " cannot be null ");
+        KafkaSource<String> source = 
KafkaActionUtils.buildKafkaSource(kafkaConfig);
+        String topic = kafkaConfig.get(KafkaConnectorOptions.TOPIC).get(0);
+        KafkaSchema kafkaSchema = new KafkaSchema(kafkaConfig, topic);
+
+        Catalog catalog =

Review Comment:
   Merged



-- 
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]

Reply via email to