hailin0 commented on code in PR #6408: URL: https://github.com/apache/seatunnel/pull/6408#discussion_r1742913404
########## seatunnel-connectors-v2/connector-kafka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/source/KafkaRecordEmitter.java: ########## @@ -0,0 +1,110 @@ +/* + * 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.seatunnel.connectors.seatunnel.kafka.source; + +import org.apache.seatunnel.api.serialization.DeserializationSchema; +import org.apache.seatunnel.api.source.Collector; +import org.apache.seatunnel.api.table.catalog.TablePath; +import org.apache.seatunnel.api.table.event.SchemaChangeEvent; +import org.apache.seatunnel.api.table.type.SeaTunnelRow; +import org.apache.seatunnel.connectors.seatunnel.common.source.reader.RecordEmitter; +import org.apache.seatunnel.connectors.seatunnel.kafka.config.MessageFormatErrorHandleWay; +import org.apache.seatunnel.format.compatible.kafka.connect.json.CompatibleKafkaConnectDeserializationSchema; + +import org.apache.kafka.clients.consumer.ConsumerRecord; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Map; + +public class KafkaRecordEmitter + implements RecordEmitter< + ConsumerRecord<byte[], byte[]>, SeaTunnelRow, KafkaSourceSplitState> { + + private static final Logger logger = LoggerFactory.getLogger(KafkaRecordEmitter.class); + private final Map<TablePath, ConsumerMetadata> mapMetadata; + private final OutputCollector<SeaTunnelRow> outputCollector; + private final MessageFormatErrorHandleWay messageFormatErrorHandleWay; + + public KafkaRecordEmitter( + Map<TablePath, ConsumerMetadata> mapMetadata, + MessageFormatErrorHandleWay messageFormatErrorHandleWay) { + this.mapMetadata = mapMetadata; + this.messageFormatErrorHandleWay = messageFormatErrorHandleWay; + this.outputCollector = new OutputCollector<>(); + } + + @Override + public void emitRecord( + ConsumerRecord<byte[], byte[]> consumerRecord, + Collector<SeaTunnelRow> collector, + KafkaSourceSplitState splitState) + throws Exception { + outputCollector.output = collector; + // todo there is an additional loss in this place for non-multi-table scenarios + DeserializationSchema<SeaTunnelRow> deserializationSchema = + mapMetadata.get(splitState.getTablePath()).getDeserializationSchema(); + try { + if (deserializationSchema instanceof CompatibleKafkaConnectDeserializationSchema) { + ((CompatibleKafkaConnectDeserializationSchema) deserializationSchema) + .deserialize(consumerRecord, outputCollector); + } else { + deserializationSchema.deserialize(consumerRecord.value(), outputCollector); + } + splitState.setCurrentOffset(consumerRecord.offset() + 1); Review Comment: Please add a comment -- 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]
