MonsterChenzhuo commented on code in PR #1827: URL: https://github.com/apache/incubator-paimon/pull/1827#discussion_r1301314788
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/action/cdc/kafka/formats/ogg/OggRecordParser.java: ########## @@ -0,0 +1,218 @@ +/* + * 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.formats.ogg; + +import org.apache.paimon.flink.action.cdc.ComputedColumn; +import org.apache.paimon.flink.action.cdc.TableNameConverter; +import org.apache.paimon.flink.action.cdc.kafka.KafkaSchema; +import org.apache.paimon.flink.action.cdc.kafka.formats.RecordParser; +import org.apache.paimon.flink.sink.cdc.CdcRecord; +import org.apache.paimon.flink.sink.cdc.RichCdcMultiplexRecord; +import org.apache.paimon.types.DataType; +import org.apache.paimon.types.DataTypes; +import org.apache.paimon.types.RowKind; + +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference; +import org.apache.paimon.shade.jackson2.com.fasterxml.jackson.databind.JsonNode; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.apache.paimon.utils.Preconditions.checkNotNull; + +/** + * Implementation of {@link RecordParser} for parsing messages in the Ogg format. + * + * <p>This parser handles records in the Ogg format and extracts relevant information to produce + * {@link RichCdcMultiplexRecord} objects. + */ +public class OggRecordParser extends RecordParser { + + private static final String FIELD_PRIMARY_KEYS = "primary_keys"; + private static final String FIELD_BEFORE = "before"; + private static final String FIELD_AFTER = "after"; + private static final String FIELD_TYPE = "op_type"; + private static final String OP_UPDATE = "U"; + private static final String OP_INSERT = "I"; + private static final String OP_DELETE = "D"; + private final List<ComputedColumn> computedColumns; + + public OggRecordParser( + boolean caseSensitive, + TableNameConverter tableNameConverter, + List<ComputedColumn> computedColumns) { + super(tableNameConverter, caseSensitive); + this.computedColumns = computedColumns; + } + + @Override + public List<RichCdcMultiplexRecord> extractRecords() { + List<RichCdcMultiplexRecord> records = new ArrayList<>(); + String type = extractString(FIELD_TYPE); + switch (type) { + case OP_UPDATE: + processRecord(root.get(FIELD_BEFORE), RowKind.UPDATE_BEFORE, records); + processRecord(root.get(FIELD_AFTER), RowKind.UPDATE_AFTER, records); Review Comment: done. -- 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]
