Repository navigation
refactor: Simplify the UUID decoding logic - #255
Merged
Merged
Conversation
martin-g
reviewed
Aug 11, 2025
| let Value::Bytes(bytes) = | ||
| decode_internal(&Schema::Bytes, names, enclosing_namespace, reader)? | ||
| else { | ||
| // Calling decode_internal with Schema::Bytes can only return a Value::Bytes or an error |
Contributor
Author
There was a problem hiding this comment.
Yes, otherwise the compiler will throw an error as it can't prove that this is the only option
martin-g
approved these changes
Aug 11, 2025
martin-g
left a comment
Member
There was a problem hiding this comment.
nit) IMO the PR title (and commit message) should be refactor: ... since the old code was working (no tests changes => same functionality)
In the original implementation we first read the length and then read the remainder either as `Fixed` if the length is 16 and `String` if it is not. It uses a temporary `Vec` to be able to backtrack if `Fixed` is wrong. The backtrack can only happen if it fails to read a `Fixed` or if it gets a different type than `Fixed` from `decode_internal`. The last case can never happen, as `decode_internal` always returns the type corresponding to the schema. The first case can only happen if there are not enough bytes, because any byte pattern is valid for `Fixed`. If `Fixed` cannot read enough bytes, than `String` won't be able to read enough bytes either. I did not add a fallback from `Uuid::from_slice` to `Uuuid::parse_str` as an UUID string is at least 32 characters, so it would fail anyway.
Kriskras99
force-pushed
the
fix/improve_uuid_decode
branch
from
August 11, 2025 15:52
6230373 to
64a2d1b
Compare
Contributor
Author
|
Good point! I've renamed and merged it |
kevinjqliu
pushed a commit
to apache/iceberg-rust
that referenced
this pull request
Sep 24, 2025
## Which issue does this PR close? `Fixed[16]` encoded UUIDs are now supported in Avro-rs: apache/avro-rs#255 This will automatically support String and Fixed[16] logical types if the `logicalType` annotation is set correctly 👍 ## What changes are included in this PR? <!-- Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates. --> ## Are these changes tested? <!-- Specify what test covers (unit test, integration test, etc.). If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? -->
DerGut
pushed a commit
to DerGut/iceberg-rust
that referenced
this pull request
Oct 6, 2025
## Which issue does this PR close? `Fixed[16]` encoded UUIDs are now supported in Avro-rs: apache/avro-rs#255 This will automatically support String and Fixed[16] logical types if the `logicalType` annotation is set correctly 👍 ## What changes are included in this PR? <!-- Provide a summary of the modifications in this PR. List the main changes such as new features, bug fixes, refactoring, or any other updates. --> ## Are these changes tested? <!-- Specify what test covers (unit test, integration test, etc.). If tests are not included in your PR, please explain why (for example, are they covered by existing tests)? -->
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.
In the original implementation we first read the length and then read the remainder either as
Fixedif the length is 16 andStringif it is not. It uses a temporaryVecto be able to backtrack ifFixedis wrong.The backtrack can only happen if it fails to read a
Fixedor if it gets a different type thanFixedfromdecode_internal. The last case can never happen, asdecode_internalalways returns the type corresponding to the schema. The first case can only happen if there are not enough bytes, because any byte pattern is valid forFixed. IfFixedcannot read enough bytes, thanStringwon't be able to read enough bytes either.I did not add a fallback from
Uuid::from_slicetoUuuid::parse_stras an UUID string is at least 32 characters, so it would fail anyway.