Repository navigation
refactor: use internal/uuid outside the root package - #2764
Conversation
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]>
zeroshade
left a comment
There was a problem hiding this comment.
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.
|
|
||
| // 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()) } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Agreed, I'll add the depguard rule in a small follow-up.
|
|
||
| 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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Makes sense, I'll add Nil() with the build-tag follow-up and switch the call sites there.
Signed-off-by: laskoviymishka <[email protected]>
This moves
table,view,udf,catalogandcmd, tests included, fromgithub.com/google/uuidtointernal/uuid, sointernal/uuid/uuid.gois the only file left that importsgoogle/uuid. The import swap was one scripted rewrite. The remaining call sites now use only whatgoogle/uuidand the Go 1.27 standard libraryuuidboth provide:uuid.Nilbecomesuuid.UUID{},NewRandomandNewStringbecomeNewandNew().String(), and the Version/Variant check on the REST idempotency key becomes the byte tests it stands for.internal/uuidgets 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.UUIDandgoogle/uuid.UUIDare the same type through aliases. In tests, theNewMD5values 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 withSetRand. Checked withgo build ./...,go vet ./...with and without-tags integration, andgo test -shorton the touched packages.The Go 1.27 build tag for
internal/uuidis left for a follow-up.Part of #2062.