zeroshade commented on code in PR #2697:
URL: https://github.com/apache/iceberg-go/pull/2697#discussion_r4722000516


##########
literals.go:
##########
@@ -1316,33 +1316,33 @@ func (f *FixedLiteral) UnmarshalBinary(data []byte) 
error {
        return nil
 }
 
-type UUIDLiteral uuid.UUID
+type UUIDLiteral UUID
 
-func (UUIDLiteral) Comparator() Comparator[uuid.UUID] {
-       return func(v1, v2 uuid.UUID) int {
+func (UUIDLiteral) Comparator() Comparator[UUID] {
+       return func(v1, v2 UUID) int {
                return bytes.Compare(v1[:], v2[:])
        }
 }
 
-func (UUIDLiteral) Type() Type         { return PrimitiveTypes.UUID }
-func (u UUIDLiteral) Value() uuid.UUID { return uuid.UUID(u) }
-func (u UUIDLiteral) Any() any         { return u.Value() }
-func (u UUIDLiteral) String() string   { return uuid.UUID(u).String() }
+func (UUIDLiteral) Type() Type       { return PrimitiveTypes.UUID }
+func (u UUIDLiteral) Value() UUID    { return UUID(u) }
+func (u UUIDLiteral) Any() any       { return u.Value() }
+func (u UUIDLiteral) String() string { return UUID(u).String() }
 func (u UUIDLiteral) To(typ Type) (Literal, error) {
        switch t := typ.(type) {
        case UUIDType:
                return u, nil
        case FixedType:
                if len(u) == t.len {
-                       v, _ := uuid.UUID(u).MarshalBinary()
+                       v, _ := UUID(u).MarshalBinary()

Review Comment:
   `MarshalBinary` is `google/uuid`-only, so this won't compile once the alias 
points at stdlib `uuid`. Since `UUID` is a `[16]byte`, `bytes.Clone(u[:])` (or 
`slices.Clone`) gives the same bytes and works with both. The same applies to 
L1345 and L1363.



##########
internal/uuid/uuid.go:
##########
@@ -0,0 +1,35 @@
+// 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 is the only place in the module that names the UUID
+// implementation, so it can be swapped for the standard library without
+// touching callers.
+package uuid
+
+import "github.com/google/uuid"
+
+type UUID = uuid.UUID
+
+var Nil = uuid.Nil

Review Comment:
   In stdlib `uuid`, `Nil` is a func (`uuid.Nil()`), so a `var Nil = uuid.Nil` 
won't port as is. It isn't used in this PR, so I'd drop it until it's needed. 
If it stays, define it so both sides can provide it (e.g. `var Nil UUID`, the 
zero value).



##########
internal/uuid/uuid.go:
##########
@@ -0,0 +1,35 @@
+// 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 is the only place in the module that names the UUID
+// implementation, so it can be swapped for the standard library without
+// touching callers.
+package uuid
+
+import "github.com/google/uuid"
+
+type UUID = uuid.UUID
+
+var Nil = uuid.Nil
+
+func New() UUID { return uuid.New() }
+
+func NewRandom() (UUID, error) { return uuid.NewRandom() }
+
+func Parse(s string) (UUID, error) { return uuid.Parse(s) }
+
+func FromBytes(b []byte) (UUID, error) { return uuid.FromBytes(b) }

Review Comment:
   `FromBytes` is needed (`UUIDLiteral.UnmarshalBinary` uses it), but stdlib 
`uuid` doesn't have it, so the stdlib side will need a hand-written length 
check + copy. Worth keeping the signature exactly `func FromBytes([]byte) 
(UUID, error)` so both build-tagged files implement the same thing.



##########
internal/uuid/uuid.go:
##########
@@ -0,0 +1,35 @@
+// 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 is the only place in the module that names the UUID
+// implementation, so it can be swapped for the standard library without
+// touching callers.
+package uuid
+
+import "github.com/google/uuid"
+
+type UUID = uuid.UUID
+
+var Nil = uuid.Nil
+
+func New() UUID { return uuid.New() }
+
+func NewRandom() (UUID, error) { return uuid.NewRandom() }

Review Comment:
   Stdlib `uuid` has no `NewRandom`. Its `New`/`NewV4` don't return an error. 
This isn't used in the root package, so I'd drop it and have callers use `New`. 
If a follow-up needs the error-returning form, a stdlib wrapper would always 
return a nil error.



##########
literals.go:
##########
@@ -1356,11 +1356,11 @@ func (u UUIDLiteral) Equals(other Literal) bool {
                return false
        }
 
-       return uuid.UUID(u) == uuid.UUID(rhs)
+       return UUID(u) == UUID(rhs)
 }
 
 func (u UUIDLiteral) MarshalBinary() (data []byte, err error) {
-       return uuid.UUID(u).MarshalBinary()
+       return UUID(u).MarshalBinary()

Review Comment:
   Same as above: `return bytes.Clone(u[:]), nil` avoids the `google/uuid`-only 
method.



##########
internal/uuid/uuid.go:
##########
@@ -0,0 +1,35 @@
+// 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 is the only place in the module that names the UUID
+// implementation, so it can be swapped for the standard library without
+// touching callers.
+package uuid
+
+import "github.com/google/uuid"
+
+type UUID = uuid.UUID
+
+var Nil = uuid.Nil
+
+func New() UUID { return uuid.New() }
+
+func NewRandom() (UUID, error) { return uuid.NewRandom() }
+
+func Parse(s string) (UUID, error) { return uuid.Parse(s) }

Review Comment:
   nit: both packages have `MustParse`, so exposing it here would let the tests 
drop the `internal.Must(uuid.Parse(...))` wrapping in `expr_json_test.go`.



##########
internal/uuid/uuid.go:
##########
@@ -0,0 +1,35 @@
+// 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 is the only place in the module that names the UUID
+// implementation, so it can be swapped for the standard library without
+// touching callers.
+package uuid
+
+import "github.com/google/uuid"
+
+type UUID = uuid.UUID

Review Comment:
   nit: since this package is the contract both build-tagged implementations 
have to satisfy, a short doc comment on each exported name, or one line in the 
package comment noting that only the API common to both `google/uuid` and 
stdlib `uuid` belongs here, would keep later additions from drifting.



-- 
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]

Reply via email to