yuxiqian commented on code in PR #6358: URL: https://github.com/apache/paimon/pull/6358#discussion_r2492536541
########## paimon-flink/paimon-flink-cdc/src/main/java/org/apache/paimon/flink/pipeline/cdc/util/PaimonToFlinkCDCDataConverter.java: ########## @@ -0,0 +1,159 @@ +/* + * 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.pipeline.cdc.util; + +import org.apache.paimon.data.InternalRow; + +import org.apache.flink.cdc.common.data.DecimalData; +import org.apache.flink.cdc.common.data.LocalZonedTimestampData; +import org.apache.flink.cdc.common.data.TimestampData; +import org.apache.flink.cdc.common.data.binary.BinaryRecordData; +import org.apache.flink.cdc.common.data.binary.BinaryStringData; +import org.apache.flink.cdc.common.event.DataChangeEvent; +import org.apache.flink.cdc.common.event.TableId; +import org.apache.flink.cdc.common.types.DataType; +import org.apache.flink.cdc.common.types.DataTypeChecks; +import org.apache.flink.cdc.runtime.typeutils.BinaryRecordDataGenerator; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** Converter from Paimon to Flink CDC data. */ +public class PaimonToFlinkCDCDataConverter { + + /** Convert Paimon row to Flink CDC data. */ + public static DataChangeEvent convertRowToDataChangeEvent( + TableId tableId, + InternalRow row, + List<InternalRow.FieldGetter> fieldGetters, + BinaryRecordDataGenerator recordDataGenerator) { + Object[] objects = new Object[row.getFieldCount()]; + for (int i = 0; i < row.getFieldCount(); i++) { + objects[i] = fieldGetters.get(i).getFieldOrNull(row); + } + BinaryRecordData binaryRecordData = recordDataGenerator.generate(objects); + switch (row.getRowKind()) { + case INSERT: + case UPDATE_AFTER: + { + return DataChangeEvent.insertEvent(tableId, binaryRecordData, new HashMap<>()); Review Comment: Flink Row encodes an update event as two separated rows (`-U` and `+U`), while CDC `UpdateEvent` carries both as one event. Seems it's not possible to build a complete `DataChangeEvent.updateEvent` with given `UPDATE_BEFORE` or `UPDATE_AFTER` row here. -- 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]
