[Feature][Kafka] Support native format read/write kafka record#8724
Conversation
| && !CollectionUtils.isEmpty(pluginConfig.get(ASSIGN_PARTITIONS))) { | ||
| MessageContentPartitioner.setAssignPartitions(pluginConfig.get(ASSIGN_PARTITIONS)); | ||
| } | ||
| isNative = pluginConfig.get(IS_NATIVE) != null && pluginConfig.get(IS_NATIVE); |
There was a problem hiding this comment.
Is it better to use Boolean.True.equals(pluginConfig.get(IS_NATIVE))?
| ConsumerRecord<String, String> oldRecord = data.get(i); | ||
| ConsumerRecord<String, String> newRecord = data.get(i); | ||
| Assertions.assertEquals(oldRecord.key(), newRecord.key()); | ||
| Assertions.assertEquals(oldRecord.headers(), newRecord.headers()); | ||
| Assertions.assertEquals(oldRecord.partition(), newRecord.partition()); | ||
| Assertions.assertEquals(oldRecord.timestamp(), newRecord.timestamp()); | ||
| Assertions.assertEquals(oldRecord.timestamp(), newRecord.timestamp()); | ||
| Assertions.assertEquals(oldRecord.value(), newRecord.value()); |
There was a problem hiding this comment.
Seems the oldRecord and newRecord are referring to the same object, what's the meaning of those assertions?
| * @param out | ||
| */ | ||
| public void deserialize(ConsumerRecord<byte[], byte[]> msg, Collector<SeaTunnelRow> out) { | ||
| tryInitConverter(); |
There was a problem hiding this comment.
Could we try to move the init logic to the constructor?
|
|
||
| @Override | ||
| public SeaTunnelRow deserialize(byte[] message) throws IOException { | ||
| throw new UnsupportedOperationException( |
There was a problem hiding this comment.
Why is it not suggested that this method be invoked?
| is_native = true | ||
| topic = "test_topic" | ||
| bootstrap.servers = "kafkaCluster:9092" | ||
| kafka.config = { | ||
| client.id = client_1 | ||
| max.poll.records = 500 | ||
| auto.offset.reset = "earliest" | ||
| enable.auto.commit = "false" | ||
| } | ||
| format = "COMPATIBLE_KAFKA_CONNECT_JSON" |
There was a problem hiding this comment.
| is_native = true | |
| topic = "test_topic" | |
| bootstrap.servers = "kafkaCluster:9092" | |
| kafka.config = { | |
| client.id = client_1 | |
| max.poll.records = 500 | |
| auto.offset.reset = "earliest" | |
| enable.auto.commit = "false" | |
| } | |
| format = "COMPATIBLE_KAFKA_CONNECT_JSON" | |
| topic = "test_topic" | |
| bootstrap.servers = "kafkaCluster:9092" | |
| kafka.config = { | |
| client.id = client_1 | |
| max.poll.records = 500 | |
| auto.offset.reset = "earliest" | |
| enable.auto.commit = "false" | |
| } | |
| format = "NATIVE" |
There was a problem hiding this comment.
…-kafka-native # Conflicts: # seatunnel-connectors-v2/connector-kafka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/source/KafkaSourceConfig.java
| ReadonlyConfig pluginConfig) { | ||
| switch (format) { | ||
| case JSON: | ||
| case NATIVE: |
There was a problem hiding this comment.
if the format is native, we shouldn't expect the content to be JSON
There was a problem hiding this comment.
Yes, content is not json.This is used to process producerRecord.
There was a problem hiding this comment.
just like:SeatTunnelRowType<topic, partition, offset, timestamp, headers<map<string,string>>, key, value>
|
|
||
| if (format == MessageFormat.NATIVE) { | ||
| tableSchema = | ||
| TableSchema.builder() |
| seaTunnelRowSerializer.serializeRow(element); | ||
| ProducerRecord<byte[], byte[]> producerRecord; | ||
| if (isNative) { | ||
| producerRecord = seaTunnelRowSerializer.serializeNativeRow(element, seaTunnelRowType); |
There was a problem hiding this comment.
Why not override topicExtractor, partitionExtractor, ...
remove this if-else
# Conflicts: # seatunnel-connectors-v2/connector-kafka/src/main/java/org/apache/seatunnel/connectors/seatunnel/kafka/source/KafkaSourceConfig.java
| .column( | ||
| PhysicalColumn.of( | ||
| KEY, PrimitiveByteArrayType.INSTANCE, 0, false, null, null)) | ||
| .column(PhysicalColumn.of(OFFSET, BasicType.LONG_TYPE, 0, false, null, null)) |
There was a problem hiding this comment.
Native writing seem does not require this value.If need to keep it?
| KEY, PrimitiveByteArrayType.INSTANCE, 0, false, null, null)) | ||
| .column(PhysicalColumn.of(OFFSET, BasicType.LONG_TYPE, 0, false, null, null)) | ||
| .column(PhysicalColumn.of(PARTITION, BasicType.INT_TYPE, 0, false, null, null)) | ||
| .column(PhysicalColumn.of(TIMESTAMP, BasicType.LONG_TYPE, 0, false, null, null)) |
There was a problem hiding this comment.
Adding TIMESTAMP_TYPE is nice for read
close #8651
Purpose of this pull request
Does this PR introduce any user-facing change?
How was this patch tested?
Check list
New License Guide
release-note.