-
Notifications
You must be signed in to change notification settings - Fork 14.7k
KAFKA-19634: Document the encoding of nullable struct #20614
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
base: trunk
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
*/ | ||
package org.apache.kafka.common.protocol.types; | ||
|
||
import org.apache.kafka.common.protocol.types.Type.DocumentedType; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
@@ -24,7 +26,10 @@ | |
/** | ||
* The schema for a compound record definition | ||
*/ | ||
public final class Schema extends Type { | ||
public final class Schema extends DocumentedType { | ||
|
||
private static final String STRUCT_TYPE_NAME = "NULLABLE_STRUCT"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current Schema class is written for a struct that's not nullable since the write() method just writes all fields without the null indicator. We should name this STRUCT and create a new NullableStruct version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The documentation for other nullable types also needs to be updated to mention the null indicator. |
||
|
||
private static final Object[] NO_VALUES = new Object[0]; | ||
|
||
private final BoundField[] fields; | ||
|
@@ -206,6 +211,19 @@ public Struct validate(Object item) { | |
} | ||
} | ||
|
||
@Override | ||
public String typeName() { | ||
return STRUCT_TYPE_NAME; | ||
} | ||
|
||
@Override | ||
public String documentation() { | ||
return "Represents a composite object or null. " + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should first say sth like "A struct is named by a string with a capitalized first letter and consists of one or more fields". |
||
"For non-null values, the first byte is an INT8 with value 1, " + | ||
"followed by the serialization of each field in the order they are defined. " + | ||
"A null value is encoded as an INT8 with value -1 and there are no following bytes."; | ||
} | ||
|
||
public void walk(Visitor visitor) { | ||
Objects.requireNonNull(visitor, "visitor must be non-null"); | ||
handleNode(this, visitor); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1116,7 +1116,8 @@ private static String toHtml() { | |
UINT16, UNSIGNED_INT32, VARINT, VARLONG, UUID, FLOAT64, | ||
STRING, COMPACT_STRING, NULLABLE_STRING, COMPACT_NULLABLE_STRING, | ||
BYTES, COMPACT_BYTES, NULLABLE_BYTES, COMPACT_NULLABLE_BYTES, | ||
RECORDS, COMPACT_RECORDS, new ArrayOf(STRING), new CompactArrayOf(COMPACT_STRING)}; | ||
RECORDS, COMPACT_RECORDS, new ArrayOf(STRING), new CompactArrayOf(COMPACT_STRING), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are multiple of existing issues with the generated schemas in https://kafka.apache.org/protocol#protocol_api_keys.
|
||
new Schema()}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you generate the website with this change? |
||
final StringBuilder b = new StringBuilder(); | ||
b.append("<table class=\"data-table\"><tbody>\n"); | ||
b.append("<tr>"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few things that we need to fix in clients/src/main/resources/common/message/README.md.