Skip to content

API, Core: Reuse VariantUtil methods through ByteBuffers#16748

Merged
amogh-jahagirdar merged 2 commits into
apache:mainfrom
rdblue:reuse-variant-util-methods
Jun 11, 2026
Merged

API, Core: Reuse VariantUtil methods through ByteBuffers#16748
amogh-jahagirdar merged 2 commits into
apache:mainfrom
rdblue:reuse-variant-util-methods

Conversation

@rdblue

@rdblue rdblue commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This refactors some methods in VariantUtil into ByteBuffers so they can be reused for the new bitmap implementation in #16747.

This also removes VariantUtil.writeBufferAbsolute that is no longer needed because ByteBuffer now has a method to write another buffer to an absolute position. All uses of this method have been replaced with ByteBuffer.put(int, ByteBuffer, int, int).

Comment thread api/src/test/java/org/apache/iceberg/util/TestByteBuffers.java
return buffer.getLong(buffer.position() + offset);
}

static float readFloat(ByteBuffer buffer, int offset) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should readFloat and readDouble be moved as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think so because they are only used here. We can always move them later, but these weren't shared originally because we didn't have other parts of the codebase that needed them.

public void testRead3ByteUnsigned() {
ByteBuffer buffer = ByteBuffer.wrap(new byte[] {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF});
assertThat(ByteBuffers.readLittleEndianUnsigned(buffer, 0, 3)).isEqualTo(16777215);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

worth adding tests for the other methods too. I think the variant tests would exercise these indirectly but good to have unit tests.

@amogh-jahagirdar amogh-jahagirdar self-requested a review June 10, 2026 19:28

@amogh-jahagirdar amogh-jahagirdar left a comment

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.

Change looks fundamentally right to me, but I think the license formatting issue that @nssalian pointed out in TestByteBuffers is legitimate

@amogh-jahagirdar amogh-jahagirdar merged commit dedb08e into apache:main Jun 11, 2026
54 checks passed
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.

3 participants