-
Notifications
You must be signed in to change notification settings - Fork 1k
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
feat: add BYTES type to ksqlDB #7778
Conversation
@Immutable | ||
public class BytesLiteral extends Literal { | ||
|
||
private final ImmutableList<Byte> value; |
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.
Doing this because ByteBuffer
and byte[]
are both mutable.
final byte[] bytes = new byte[requireNonNull(value, "value").capacity()]; | ||
value.get(bytes); | ||
this.value = ImmutableList.copyOf(ArrayUtils.toObject(bytes)); |
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.
What if you keep the final byte[] bytes
at the class variable instead of the ImmutableList<Byte>
? The value.get(bytes)
will copy everything from ByteBuffer -> bytes, so you have an exact immutable copy.
Later, when you call getValue()
, you can return ByteBuffer.wrap(bytes).asReadOnlyBuffer()
to avoid the returned byte buffer can be modified.
And, when you call getByteArray()
, then clone the array
return bytes == null ? null : bytes.clone();
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.
Yeah that works!
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.
LGTM
Description
Adds SqlTypes.BYTES and BytesLiteral to ksqlDB. The main KLIP, #7764, is not merged yet but this PR is almost 100% wiring with no logic, so I'm filing this now to prep for future BYTES work.
Testing done
Updated unit tests
Reviewer checklist