close
Skip to content

[Feature][Kafka] Support native format read/write kafka record#8724

Merged
Hisoka-X merged 22 commits into
apache:devfrom
CosmosNi:feature-kafka-native
Mar 3, 2025
Merged

[Feature][Kafka] Support native format read/write kafka record#8724
Hisoka-X merged 22 commits into
apache:devfrom
CosmosNi:feature-kafka-native

Conversation

@CosmosNi

Copy link
Copy Markdown
Collaborator

close #8651

Purpose of this pull request

Does this PR introduce any user-facing change?

How was this patch tested?

Check list

&& !CollectionUtils.isEmpty(pluginConfig.get(ASSIGN_PARTITIONS))) {
MessageContentPartitioner.setAssignPartitions(pluginConfig.get(ASSIGN_PARTITIONS));
}
isNative = pluginConfig.get(IS_NATIVE) != null && pluginConfig.get(IS_NATIVE);

@litiliu litiliu Feb 14, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use Boolean.True.equals(pluginConfig.get(IS_NATIVE))?

Comment on lines +195 to +202
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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we try to move the init logic to the constructor?


@Override
public SeaTunnelRow deserialize(byte[] message) throws IOException {
throw new UnsupportedOperationException(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it not suggested that this method be invoked?

Comment thread docs/en/connector-v2/source/Kafka.md Outdated
Comment on lines +381 to +390
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadonlyConfig pluginConfig) {
switch (format) {
case JSON:
case NATIVE:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the format is native, we shouldn't expect the content to be JSON

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, content is not json.This is used to process producerRecord.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just like:SeatTunnelRowType<topic, partition, offset, timestamp, headers<map<string,string>>, key, value>


if (format == MessageFormat.NATIVE) {
tableSchema =
TableSchema.builder()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to static final field

seaTunnelRowSerializer.serializeRow(element);
ProducerRecord<byte[], byte[]> producerRecord;
if (isNative) {
producerRecord = seaTunnelRowSerializer.serializeNativeRow(element, seaTunnelRowType);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not override topicExtractor, partitionExtractor, ...

remove this if-else

Comment thread docs/en/connector-v2/sink/Kafka.md
@CosmosNi CosmosNi requested a review from hailin0 February 21, 2025 07:22
@CosmosNi CosmosNi requested a review from hailin0 February 26, 2025 01:53
.column(
PhysicalColumn.of(
KEY, PrimitiveByteArrayType.INSTANCE, 0, false, null, null))
.column(PhysicalColumn.of(OFFSET, BasicType.LONG_TYPE, 0, false, null, null))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why delete it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Native writing seem does not require this value.If need to keep it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is useful for read

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding TIMESTAMP_TYPE is nice for read

@hailin0 hailin0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @CosmosNi

@Hisoka-X Hisoka-X merged commit 86e2d6f into apache:dev Mar 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature][Kafka] Support native format read/write kafka record

4 participants