Spark: Avoid String and java.util.UUID allocations on UUID read/write paths - #16349
Open
wombatu-kun wants to merge 2 commits into
Open
Spark: Avoid String and java.util.UUID allocations on UUID read/write paths#16349wombatu-kun wants to merge 2 commits into
wombatu-kun wants to merge 2 commits into
Conversation
wombatu-kun
marked this pull request as draft
May 15, 2026 11:26
wombatu-kun
marked this pull request as ready for review
May 15, 2026 12:46
wombatu-kun
force-pushed
the
spark-uuid-direct-conversion
branch
from
May 20, 2026 12:46
0b34b4f to
8392840
Compare
wombatu-kun
force-pushed
the
spark-uuid-direct-conversion
branch
from
May 22, 2026 10:15
8392840 to
748fec8
Compare
|
This pull request has been marked as stale due to 30 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@iceberg.apache.org list. Thank you for your contributions. |
Contributor
Author
|
no stale |
wombatu-kun
force-pushed
the
spark-uuid-direct-conversion
branch
from
August 4, 2026 02:45
748fec8 to
661a3c1
Compare
… paths Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Use a local accumulator instead of mutating the `value` parameter so checkstyle's ParameterAssignment rule passes. Behavior is byte-for-byte unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
wombatu-kun
force-pushed
the
spark-uuid-direct-conversion
branch
from
August 11, 2026 05:12
661a3c1 to
082d49c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
This implements the existing
// TODO: direct conversion from string to byte bufferinSparkValueWriters. The Spark data layer converted UUID values through an intermediateStringand ajava.util.UUIDobject on every value, in both directions: write didUUID.fromString(s.toString())then re-serialized the two longs to 16 bytes; read didUUIDUtil.convert(buf).toString()then wrapped that asUTF8String. The UUID arrives as the ASCII bytes of its canonical string and leaves as 16 raw bytes (and vice versa), so theString/UUIDobjects are pure per-row allocation overhead.Changes
UUIDUtil.convertToByteBuffer(byte[] uuidStringBytes, ByteBuffer reuse)— parses the 36 ASCII bytes of a canonical UUID string directly into the 16-byte big-endian form.UUIDUtil.convertToStringBytes(ByteBuffer uuidBytes, byte[] reuse)— renders 16 bytes back to the 36 ASCII bytes of the canonical string.Spark*Readers/Spark*Writersfor Spark 4.1 to use these helpers. The change is identical for 3.5 and 4.0; a backport PR will follow.TestUUIDUtilcoverage for the new methods.Correctness
Both helpers pivot on the
(mostSigBits, leastSigBits)long pair: the parser reproducesjava.util.UUID.fromString(parse[0,8)→<<16 | [9,13)→<<16 | [14,18)for MSB;[19,23)→<<48 | [24,36)for LSB) and thenputLong(0, msb); putLong(8, lsb)exactly as the previousconvertToByteBuffer(UUID, reuse); the formatter is the inverse and matchesUUID.toString(). The output is therefore byte-for-byte identical to the previous code. The write side keeps the reusable thread-local buffer; the read side must allocate a fresh array becauseUTF8String.fromByteswraps without copying (a reused buffer would alias across rows).AI Disclosure