Open
Conversation
Add optional uuid feature to support reading/writing UUID types from Spanner. The emulator supports UUID since v1.5.46, but the Rust SDK lacked TryFromValue implementation. - Add uuid crate as optional dependency with 'uuid' feature flag - Implement TryFromValue for uuid::Uuid (parse from StringValue) - Implement ToKind for uuid::Uuid (serialize to StringValue with TypeCode::Uuid) - Add tests for both serialization and deserialization
Prevent UUID parsing from being attempted on non-UUID columns. Now TryFromValue for uuid::Uuid checks TypeCode::Uuid before parsing, returning a clear error if the column type doesn't match.
Expose Field metadata to allow callers to inspect TypeCode before reading values. Useful for: - Distinguishing BYTES vs STRING (both use StringValue) - Checking array element types - Validating JSON column types
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.
Summary
uuidfeature to support reading/writing UUID types from SpannerTryFromValueimplementationRow::field()andRow::field_by_name()getters to expose column metadataChanges
UUID Support
uuidcrate as optional dependency withuuidfeature flagTryFromValue for uuid::Uuid(parse from StringValue with TypeCode validation)ToKind for uuid::Uuid(serialize to StringValue withTypeCode::Uuid)Field Metadata Access
Row::field(column_index)→ returnsOption<&Field>Row::field_by_name(column_name)→ returnsOption<&Field>Usage
UUID
Field Metadata (for ORM/dynamic type handling)
Why these changes?
Why StringValue for UUID?
Spanner gRPC protocol uses
google.protobuf.Valuewhich has no UUID-specific kind. All complex types (INT64, NUMERIC, BYTES, DATE, UUID, etc.) are encoded asstring_value. TheTypeCode::Uuidis schema metadata, not wire format.Why TypeCode validation in UUID?
Without validation, attempting to read a UUID from a non-UUID column (e.g., STRING) would try to parse any string as UUID, causing confusing errors. Now it fails fast with a clear type mismatch error.
Why Field getters?
Several Spanner types share the same wire format (e.g., BYTES and STRING both use StringValue). ORM layers need to inspect
TypeCodeto determine the correct Rust type. The field getters expose this metadata without breaking the existing API.