package extensions
import (
"encoding/json"
"fmt"
"reflect"
"unsafe"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
)
type OpaqueType struct {
arrow .ExtensionBase `json:"-"`
TypeName string `json:"type_name"`
VendorName string `json:"vendor_name"`
}
func NewOpaqueType (storageType arrow .DataType , name , vendorName string ) *OpaqueType {
return &OpaqueType {ExtensionBase : arrow .ExtensionBase {Storage : storageType },
TypeName : name , VendorName : vendorName }
}
func (*OpaqueType ) ArrayType () reflect .Type {
return reflect .TypeOf (OpaqueArray {})
}
func (*OpaqueType ) ExtensionName () string {
return "arrow.opaque"
}
func (o *OpaqueType ) String () string {
return fmt .Sprintf ("extension<%s[storage_type=%s, type_name=%s, vendor_name=%s]>" ,
o .ExtensionName (), o .Storage , o .TypeName , o .VendorName )
}
func (o *OpaqueType ) Serialize () string {
data , _ := json .Marshal (o )
return string (data )
}
func (*OpaqueType ) Deserialize (storageType arrow .DataType , data string ) (arrow .ExtensionType , error ) {
var out OpaqueType
err := json .Unmarshal (unsafe .Slice (unsafe .StringData (data ), len (data )), &out )
if err != nil {
return nil , err
}
switch {
case out .TypeName == "" :
return nil , fmt .Errorf ("%w: serialized JSON data for OpaqueType missing type_name" ,
arrow .ErrInvalid )
case out .VendorName == "" :
return nil , fmt .Errorf ("%w: serialized JSON data for OpaqueType missing vendor_name" ,
arrow .ErrInvalid )
}
out .ExtensionBase = arrow .ExtensionBase {Storage : storageType }
return &out , nil
}
func (o *OpaqueType ) ExtensionEquals (other arrow .ExtensionType ) bool {
if o .ExtensionName () != other .ExtensionName () {
return false
}
rhs , ok := other .(*OpaqueType )
if !ok {
return false
}
return arrow .TypeEqual (o .Storage , rhs .Storage ) &&
o .TypeName == rhs .TypeName &&
o .VendorName == rhs .VendorName
}
type OpaqueArray struct {
array .ExtensionArrayBase
}
var (
_ arrow .ExtensionType = (*OpaqueType )(nil )
_ array .ExtensionArray = (*OpaqueArray )(nil )
)
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .