lvyanquan commented on code in PR #3904:
URL: https://github.com/apache/flink-cdc/pull/3904#discussion_r1991387033


##########
flink-cdc-connect/flink-cdc-pipeline-connectors/flink-cdc-pipeline-connector-iceberg/src/main/java/org/apache/flink/cdc/connectors/iceberg/sink/utils/IcebergTypeUtils.java:
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.flink.cdc.connectors.iceberg.sink.utils;
+
+import org.apache.flink.cdc.common.data.DecimalData;
+import org.apache.flink.cdc.common.data.RecordData;
+import org.apache.flink.cdc.common.schema.Column;
+import org.apache.flink.cdc.common.schema.PhysicalColumn;
+import org.apache.flink.cdc.common.schema.Schema;
+import org.apache.flink.cdc.common.types.DataType;
+import org.apache.flink.cdc.common.types.DataTypeChecks;
+import org.apache.flink.cdc.common.types.DataTypes;
+import org.apache.flink.cdc.connectors.iceberg.sink.IcebergDataSink;
+
+import org.apache.iceberg.types.Type;
+import org.apache.iceberg.types.TypeUtil;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.DateTimeUtil;
+import org.apache.iceberg.util.DecimalUtil;
+
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.util.ArrayList;
+import java.util.List;
+
+import static org.apache.flink.cdc.common.types.DataTypeChecks.getFieldCount;
+
+/** Util class for {@link IcebergDataSink}. */
+public class IcebergTypeUtils {
+
+    /** Convert column from CDC framework to Iceberg framework. */
+    public static Types.NestedField convertCDCColumnToIcebergField(
+            int index, PhysicalColumn column) {
+        DataType dataType = column.getType();
+        return Types.NestedField.of(
+                index,
+                dataType.isNullable(),
+                column.getName(),
+                convertCDCTypeToIcebergType(dataType),
+                column.getComment());
+    }
+
+    /** Convert data type from CDC framework to Iceberg framework, refer to <a 
href="https://iceberg.apache.org/docs/nightly/flink/#flink-to-iceberg";>...</a>. 
*/
+    public static Type convertCDCTypeToIcebergType(DataType type) {
+        // ordered by type root definition
+        List<DataType> children = type.getChildren();
+        int length = DataTypes.getLength(type).orElse(0);
+        int precision = DataTypes.getPrecision(type).orElse(0);
+        int scale = DataTypes.getScale(type).orElse(0);
+        switch (type.getTypeRoot()) {
+            case CHAR:
+            case VARCHAR:
+                return new Types.StringType();
+            case BOOLEAN:
+                return new Types.BooleanType();
+            case BINARY:
+            case VARBINARY:
+                return new Types.BinaryType();

Review Comment:
   Refer to type mapping 
https://nightlies.apache.org/flink/flink-cdc-docs-release-3.3/docs/connectors/pipeline-connectors/mysql/#data-type-mapping
 in FlinkCDC, BIT type will be mapping to BOOLEAN type.
   
   



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