Skip to content

Commit 7fe9990

Browse files
authored
chore(UUID): Streamline UUID implementation (#851)
Based on apache/arrow#35457 review
1 parent fb5d5c6 commit 7fe9990

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

types/uuid.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ func (b *UUIDBuilder) AppendValueFromString(s string) error {
3737
return nil
3838
}
3939

40-
b.Append(uuid.MustParse(s))
40+
uid, err := uuid.Parse(s)
41+
if err != nil {
42+
return err
43+
}
44+
45+
b.Append(uid)
4146
return nil
4247
}
4348

@@ -172,7 +177,7 @@ func (a *UUIDArray) GetOneForMarshal(i int) any {
172177
if a.IsNull(i) {
173178
return nil
174179
}
175-
return uuid.Must(uuid.FromBytes(a.Storage().(*array.FixedSizeBinary).Value(i)))
180+
return a.Value(i)
176181
}
177182

178183
// UUIDType is a simple extension type that represents a FixedSizeBinary(16)
@@ -181,7 +186,7 @@ type UUIDType struct {
181186
arrow.ExtensionBase
182187
}
183188

184-
// NewUUIDType is a convenience function to create an instance of UuidType
189+
// NewUUIDType is a convenience function to create an instance of UUIDType
185190
// with the correct storage type
186191
func NewUUIDType() *UUIDType {
187192
return &UUIDType{ExtensionBase: arrow.ExtensionBase{Storage: &arrow.FixedSizeBinaryType{ByteWidth: 16}}}
@@ -210,13 +215,13 @@ func (*UUIDType) Serialize() string {
210215
}
211216

212217
// Deserialize expects storageType to be FixedSizeBinaryType{ByteWidth: 16} and the data to be
213-
// "uuid-serialized" in order to correctly create a UuidType for testing deserialize.
218+
// "uuid-serialized" in order to correctly create a UUIDType for testing deserialize.
214219
func (*UUIDType) Deserialize(storageType arrow.DataType, data string) (arrow.ExtensionType, error) {
215220
if data != "uuid-serialized" {
216221
return nil, fmt.Errorf("type identifier did not match: '%s'", data)
217222
}
218223
if !arrow.TypeEqual(storageType, &arrow.FixedSizeBinaryType{ByteWidth: 16}) {
219-
return nil, fmt.Errorf("invalid storage type for UuidType: %s", storageType.Name())
224+
return nil, fmt.Errorf("invalid storage type for UUIDType: %s", storageType.Name())
220225
}
221226
return NewUUIDType(), nil
222227
}

0 commit comments

Comments
 (0)