Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-14425; The Kafka protocol should support nullable structs #12932

Merged
merged 4 commits into from
Dec 8, 2022

Conversation

dajac
Copy link
Contributor

@dajac dajac commented Dec 1, 2022

KIP: https://cwiki.apache.org/confluence/display/KAFKA/KIP-893%3A+The+Kafka+protocol+should+support+nullable+structs

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@dajac dajac added the kip Requires or implements a KIP label Dec 1, 2022
@dajac dajac changed the title [WIP] KAFKA-14425; The Kafka protocol should support nullable structs KAFKA-14425; The Kafka protocol should support nullable structs Dec 6, 2022
@dajac dajac added the KIP-848 label Dec 6, 2022
@dajac
Copy link
Contributor Author

dajac commented Dec 6, 2022

@cmccabe Could you review this one please? The vote is not closed yet but we have all the votes.

@cmccabe
Copy link
Contributor

cmccabe commented Dec 7, 2022

Thanks for this, @dajac . Can you add a test that the Invalid default for struct field message appears as expected when the default is set to something other than null? MessageDataGeneratorTest.java has some examples of tests like that

The other test that I really want is a test that a tagged nullable struct will be correctly ignored by code prior to this PR. Unfortunately I don't have a good suggestion for how to do that in junit or ducktape. Can you do some kind of manual test to ensure that this is the case?

(Once we have people using tagged nullable structs the ducktape cross-version compatibility tests will serve as a de-facto test of this, but that will come later)

@dajac
Copy link
Contributor Author

dajac commented Dec 7, 2022

Can you add a test that the Invalid default for struct field message appears as expected when the default is set to something other than null? MessageDataGeneratorTest.java has some examples of tests like that

That makes sense. Added tests.

The other test that I really want is a test that a tagged nullable struct will be correctly ignored by code prior to this PR. Unfortunately I don't have a good suggestion for how to do that in junit or ducktape. Can you do some kind of manual test to ensure that this is the case?

I did the following. With this PR, I used the following schema and code to serialize a message.

{
  "name": "TestMessage",
  "type": "header",
  "validVersions": "0",
  "flexibleVersions": "0+",
  "fields": [
    { "name": "struct1", "type": "Struct", "versions": "0+", "nullableVersions": "0+", "default": "null",
      "tag": 1, "taggedVersions": "0+", "fields": [
        { "name": "int1", "type": "int32", "versions": "0+" }
      ]
    },
    { "name": "int0", "type": "int32", "versions": "0+", "tag": 0, "taggedVersions": "0+" }
  ]
}
        TestMessageData.Struct struct = new TestMessageData.Struct()
            .setInt1(100);
        TestMessageData message = new TestMessageData()
            .setStruct1(struct)
            .setInt0(200);

        ByteBuffer buffer = MessageUtil.toByteBuffer(message, (short) 0);
        FileChannel fc = new FileOutputStream("/tmp/test-message").getChannel();
        fc.write(buffer);
        fc.close();

Then, with trunk, I used the following schema and code to validate.

{
  "name": "TestMessage",
  "type": "header",
  "validVersions": "0",
  "flexibleVersions": "0+",
  "fields": [
    { "name": "int0", "type": "int32", "versions": "0+", "tag": 0, "taggedVersions": "0+" }
  ]
}
        FileChannel fc = new FileInputStream("/tmp/test-message").getChannel();
        ByteBuffer buffer = ByteBuffer.allocate((int) fc.size());
        fc.read(buffer);
        fc.close();
        buffer.flip();

        TestMessageData message = new TestMessageData();
        message.read(new ByteBufferAccessor(buffer), (short) 0);

        assertEquals(200, message.int0());
        assertEquals(1, message.unknownTaggedFields().size());

That worked as expected.

@dajac dajac marked this pull request as ready for review December 8, 2022 19:18
@dajac
Copy link
Contributor Author

dajac commented Dec 8, 2022

The KIP has been accepted.

Copy link
Contributor

@cmccabe cmccabe left a comment

Choose a reason for hiding this comment

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

LGTM

@dajac dajac merged commit a0c19c0 into apache:trunk Dec 8, 2022
@dajac dajac deleted the KAFKA-14425 branch December 8, 2022 19:54
guozhangwang pushed a commit to guozhangwang/kafka that referenced this pull request Jan 25, 2023
…he#12932)

This patch adds support for nullable structs in the Kafka protocol as described in KIP-893 - https://cwiki.apache.org/confluence/display/KAFKA/KIP-893%3A+The+Kafka+protocol+should+support+nullable+structs.

Reviewers: Colin Patrick McCabe <cmccabe@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kip Requires or implements a KIP KIP-848
Projects
None yet
2 participants