junrao commented on code in PR #20614: URL: https://github.com/apache/kafka/pull/20614#discussion_r2543324218
########## clients/src/main/java/org/apache/kafka/common/protocol/types/NullableSchema.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.kafka.common.protocol.types; + +import java.nio.ByteBuffer; +import java.util.Arrays; + +/** + * The nullable schema for a compound record definition + */ +public final class NullableSchema extends Schema { + + private static final String NULLABLE_STRUCT_TYPE_NAME = "NULLABLE_STRUCT"; + + public NullableSchema(Field... fs) { + this(false, fs); + } + + public NullableSchema(boolean tolerateMissingFieldsWithDefaults, Field... fs) { + super(tolerateMissingFieldsWithDefaults, fs); + } + + public NullableSchema(Schema schema) { Review Comment: Could we only keep this constructor? ########## clients/src/main/java/org/apache/kafka/common/protocol/types/ArrayOf.java: ########## @@ -119,15 +132,25 @@ public Object[] validate(Object item) { @Override public String typeName() { - return ARRAY_TYPE_NAME; + return nullable ? NULLABLE_ARRAY_TYPE_NAME : ARRAY_TYPE_NAME; } @Override public String documentation() { - return "Represents a sequence of objects of a given type T. " + + String doc; + if (nullable) { + doc = "Represents a sequence of objects of a given type T. " + "Type T can be either a primitive type (e.g. " + STRING + ") or a structure. " + "First, the length N is given as an " + INT32 + ". Then N instances of type T follow. " + "A null array is represented with a length of -1. " + + "In protocol documentation a nullable array of T instances is referred to as [T]?."; Review Comment: [T]? => ?[T] ########## clients/src/main/java/org/apache/kafka/common/protocol/types/CompactArrayOf.java: ########## @@ -125,15 +138,24 @@ public Object[] validate(Object item) { @Override public String typeName() { - return COMPACT_ARRAY_TYPE_NAME; + return nullable ? COMPACT_NULLABLE_ARRAY_TYPE_NAME : COMPACT_ARRAY_TYPE_NAME; } @Override public String documentation() { - return "Represents a sequence of objects of a given type T. " + + String doc; + if (nullable) { + doc = "Represents a sequence of objects of a given type T. " + "Type T can be either a primitive type (e.g. " + STRING + ") or a structure. " + "First, the length N + 1 is given as an UNSIGNED_VARINT. Then N instances of type T follow. " + "A null array is represented with a length of 0. " + - "In protocol documentation an array of T instances is referred to as [T]."; + "In protocol documentation a compact nullable array of T instances is referred to as (T)?."; Review Comment: [T]? => ?[T] ########## clients/src/main/java/org/apache/kafka/common/protocol/types/Type.java: ########## @@ -79,6 +79,14 @@ public final boolean isArray() { return arrayElementType().isPresent(); } + public String leftBracket() { Review Comment: Could we add the javadoc for the new methods? ########## clients/src/main/java/org/apache/kafka/common/protocol/types/Schema.java: ########## @@ -53,6 +58,7 @@ public Schema(Field... fs) { * * @throws SchemaException If the given list have duplicate fields */ + @SuppressWarnings("this-escape") Review Comment: Why is this needed? ########## clients/src/main/java/org/apache/kafka/common/protocol/types/BoundField.java: ########## @@ -30,6 +30,10 @@ public BoundField(Field def, Schema schema, int index) { this.index = index; } + public Field def() { + return this.def; Review Comment: Do we need this? def is a public field. ########## clients/src/main/java/org/apache/kafka/common/protocol/types/Schema.java: ########## @@ -173,6 +179,20 @@ public BoundField[] fields() { return this.fields; } + public boolean tolerateMissingFieldsWithDefaults() { Review Comment: Could this be protected instead of public? ########## streams/src/test/java/org/apache/kafka/streams/tests/EosTestDriver.java: ########## @@ -246,7 +246,7 @@ public static void verify(final String kafka, final boolean withRepartitioning, } // do not modify: required test output - System.out.println("ALL-RECORDS-DELIVERED"); + System.out.println("ALL-NULLABLE_RECORDS-DELIVERED"); Review Comment: Hmm, why do we need to change this? Are records nullable? ########## clients/src/main/java/org/apache/kafka/common/protocol/types/Schema.java: ########## @@ -24,7 +26,10 @@ /** * The schema for a compound record definition */ -public final class Schema extends Type { +public class Schema extends DocumentedType { + Review Comment: extra line -- 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]
