laskoviymishka commented on code in PR #2766: URL: https://github.com/apache/iceberg-go/pull/2766#discussion_r4749266464
########## 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: Added the fast path in 0747769ef3. I left out the google/uuid case in uuid_std.go so google/uuid stays in uuid_google.go only. On 1.27 the reflection path now only runs for arrow-go's UUID type. ########## 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: Fixed in 0747769ef3 -- 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]
