Skip to content

refactor: use internal/uuid outside the root package - #2764

Merged
laskoviymishka merged 2 commits into
apache:mainfrom
laskoviymishka:factory/uuid-other-packages
Dec 1, 2026
Merged

laskoviymishka merged 2 commits into
apache:mainfrom
laskoviymishka:factory/uuid-other-packages

Conversation

@laskoviymishka

Copy link
Copy Markdown
Contributor

This moves table, view, udf, catalog and cmd, tests included, from github.com/google/uuid to internal/uuid, so internal/uuid/uuid.go is the only file left that imports google/uuid. The import swap was one scripted rewrite. The remaining call sites now use only what google/uuid and the Go 1.27 standard library uuid both provide: uuid.Nil becomes uuid.UUID{}, NewRandom and NewString become New and New().String(), and the Version/Variant check on the REST idempotency key becomes the byte tests it stands for. internal/uuid gets one new function, NewV7, which the idempotency key needs.

There is no behavior change and no exported signature changes type, because iceberg.UUID, internal/uuid.UUID and google/uuid.UUID are the same type through aliases. In tests, the NewMD5 values are now fixed literals with the same value, and the metadata file location tests check the shape of the path instead of pinning the random source with SetRand. Checked with go build ./..., go vet ./... with and without -tags integration, and go test -short on the touched packages.

The Go 1.27 build tag for internal/uuid is left for a follow-up.

Part of #2062.

AI-assisted, reviewed by a human.

Switch table, view, udf, catalog and cmd, tests included, from
github.com/google/uuid to internal/uuid. internal/uuid/uuid.go is now
the only file in the module that imports google/uuid.

Call sites use only the API that google/uuid and the Go 1.27 standard
library uuid package share. uuid.Nil becomes the zero value
uuid.UUID{}, NewRandom and Must(NewRandom()) become New, NewString
becomes New().String(), and the Version/Variant check on the REST
idempotency key becomes the equivalent tests on bytes 6 and 8.
internal/uuid gains NewV7 for the idempotency key. In tests, NewMD5
values become fixed MustParse literals and the metadata file location
tests check the shape of the path instead of pinning the random source
with SetRand.

No behavior change. iceberg.UUID, internal/uuid.UUID and google/uuid's
UUID are the same type through aliases, so no exported signature
changes.

Signed-off-by: laskoviymishka <[email protected]>
@laskoviymishka
laskoviymishka marked this pull request as ready for review November 29, 2026 15:14

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks! internal/uuid/uuid.go is now the only importer of google/uuid, and every remaining call site uses API that both google/uuid and the stdlib uuid provide. I checked the non-mechanical changes: the version/variant byte tests match the RFC 9562 layout, and the NewMD5 literals are the same values. go build ./..., go vet ./... (with and without -tags integration) and go test -short on the touched packages pass locally.

nit: NewRandom → New and the new NewV7 panic instead of returning an error. That's not a real behavior change on Go ≥ 1.24, where crypto/rand.Read never fails, but one sentence in the description saying so would answer the obvious question about the removed error branches.

Comment thread internal/uuid/uuid.go

// NewV7 returns a time-ordered (version 7) UUID. It panics if the random
// source fails, as New does.
func NewV7() UUID { return uuid.Must(uuid.NewV7()) }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: nothing stops someone from importing github.com/google/uuid again outside this package, and the build-tag swap would then silently miss that file. A depguard rule in .golangci.yml that denies it everywhere except internal/uuid would catch it in lint. There's no depguard config today, so this could be a small follow-up.

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.

Agreed, I'll add the depguard rule in a small follow-up.

Comment thread table/table.go

func validateTableUUID(identifier Identifier, expected, actual uuid.UUID) error {
if expected == uuid.Nil || actual == uuid.Nil || expected == actual {
if expected == (uuid.UUID{}) || actual == (uuid.UUID{}) || expected == actual {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: == (uuid.UUID{}) now appears about ten times (table/view/udf builders, here, tests). The stdlib has uuid.Nil() as a function, so a func Nil() UUID (or IsZero) in internal/uuid would work on both sides of the swap and read better. Fine to leave for the build-tag follow-up.

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.

Makes sense, I'll add Nil() with the build-tag follow-up and switch the call sites there.

@laskoviymishka
laskoviymishka merged commit 05ff00c into apache:main Dec 1, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants