yevgenypats commented on code in PR #34454:
URL: https://github.com/apache/arrow/pull/34454#discussion_r1127414058
##########
go/arrow/internal/testing/types/extension_types.go:
##########
@@ -18,26 +18,181 @@
package types
import (
+ "bytes"
"encoding/binary"
"fmt"
"reflect"
+ "strings"
+
+ "github.com/goccy/go-json"
"github.com/apache/arrow/go/v12/arrow"
"github.com/apache/arrow/go/v12/arrow/array"
+ "github.com/apache/arrow/go/v12/arrow/memory"
+ "github.com/google/uuid"
"golang.org/x/xerrors"
)
+type UUIDBuilder struct {
+ *array.ExtensionBuilder
+ dtype *UUIDType
+}
+
+func NewUUIDBuilder(mem memory.Allocator, dtype arrow.ExtensionType)
*UUIDBuilder {
+ b := &UUIDBuilder{
+ ExtensionBuilder: array.NewExtensionBuilder(mem, dtype),
+ dtype: dtype.(*UUIDType),
+ }
+ return b
+}
+
+func (b *UUIDBuilder) Append(v uuid.UUID) {
+ b.ExtensionBuilder.Builder.(*array.FixedSizeBinaryBuilder).Append(v[:])
+}
+
+func (b *UUIDBuilder) UnsafeAppend(v uuid.UUID) {
+
b.ExtensionBuilder.Builder.(*array.FixedSizeBinaryBuilder).UnsafeAppend(v[:])
+}
+
+func (b *UUIDBuilder) AppendValues(v []uuid.UUID, valid []bool) {
+ data := make([][]byte, len(v))
+ for i, v := range v {
+ data[i] = v[:]
+ }
+
b.ExtensionBuilder.Builder.(*array.FixedSizeBinaryBuilder).AppendValues(data,
valid)
+}
+
+func (b *UUIDBuilder) UnmarshalOne(dec *json.Decoder) error {
+ t, err := dec.Token()
Review Comment:
If you don't implement `UnmarshalOne` this should call the underlying
ExtensionBuilder `UnmarshalOne`. This part was critical for us because
otherwise we can't use any of `Marshal`, `Unmarshal` functions as they will
always result `base64` encoded values instead of what is a fit for the
extension. For UUID for example we want to unmarshal a uuid or in case of IP
Address (a string of ip address while storing this as a binary).
Here is an example of a few types we implemented on top of this PR:
https://github.com/cloudquery/filetypes/tree/main/internal/cqarrow (This is
just a PoC and will eventually go into our
[SDK](https://github.com/cloudquery/plugin-sdk) which is used by all our
[plugins](https://github.com/cloudquery/cloudquery) )
--
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]