zeroshade commented on code in PR #2766: URL: https://github.com/apache/iceberg-go/pull/2766#discussion_r4743998231
########## internal/uuid/uuid_std.go: ########## @@ -0,0 +1,51 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//go:build go1.27 + +package uuid + +import ( + "fmt" + "uuid" +) + +// UUID is a 16-byte RFC 9562 UUID. +type UUID = uuid.UUID + +// New returns a random (version 4) UUID. +func New() UUID { return uuid.New() } + +// Parse decodes s into a UUID. +func Parse(s string) (UUID, error) { return uuid.Parse(s) } + +// MustParse is like Parse but panics if s cannot be parsed. +func MustParse(s string) UUID { return uuid.MustParse(s) } + +// FromBytes returns the UUID held in b, which must be exactly 16 bytes long. +func FromBytes(b []byte) (UUID, error) { Review Comment: nit: `internal/uuid` has no tests, and this hand-written `FromBytes` is only covered indirectly through `UUIDLiteral.UnmarshalBinary`. Since CI runs both Go versions, a small `uuid_test.go` would check that both builds behave the same: `FromBytes` rejects 15/17 bytes, `NewV7` has version 7 and variant `0b10`, and `FromArray` accepts `[16]byte`/`UUID` and rejects non-arrays. ########## internal/uuid/convert.go: ########## @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Package uuid wraps the UUID implementation so it can be swapped for the +// standard library without touching callers, which should use this package +// instead of naming the implementation. Only API that both +// google/uuid and the standard library uuid package can provide +// belongs here. +// +// uuid_google.go builds on google/uuid before Go 1.27 and +// uuid_std.go on the standard library from Go 1.27 on. +package uuid + +import "reflect" + +// PassTo calls f with u converted to f's 16-byte UUID type, for APIs such +// as arrow-go's that name a specific UUID implementation. +func PassTo[T ~[16]byte](f func(T) error, u UUID) error { return f(T(u)) } + +// FromArray converts v, a value of any 16-byte UUID type such as the one +// arrow-go's variant values hold, to UUID. +func FromArray(v any) (UUID, bool) { Review Comment: nit: this runs once per value in `CastVariant` (`exactVariantMatch`) and `literalFromVariant`, and `reflect.ValueOf` → `Convert` → `Interface` allocates each time. Two cheaper options: a fast path `if u, ok := v.(UUID); ok { return u, true }` (covers every call before Go 1.27), and/or importing `google/uuid` in `uuid_std.go` just for a `case googleuuid.UUID: return UUID(x), true`. It's already a transitive dependency through arrow-go and stays confined to `internal/uuid`. That would remove reflection on 1.27 too, keeping it only as the fallback for unknown types. ########## internal/uuid/convert.go: ########## @@ -0,0 +1,43 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +// Package uuid wraps the UUID implementation so it can be swapped for the Review Comment: nit: the package comment now sits next to the arrow-go conversion helpers. A small `doc.go` holding only the package comment would be easier to find. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
