Documentation ¶
Overview ¶
Package anyarrow provides a convenient accessor to arrow arrays.
instead of figuring out the type, the user can simply create a new Int8 by using NewInt8 with arrow.Array, which implements the arrow.Array interface and have a [Value] function that returns an int8 by performing the proper cast.
arrow's dictionary, which is categorical data, is also supported.
Example ¶
package main import ( "fmt" "github.com/fardream/anyarrow" "github.com/apache/arrow/go/v15/arrow/array" "github.com/apache/arrow/go/v15/arrow/memory" ) func main() { mem := memory.NewGoAllocator() ab := array.NewFloat32Builder(mem) defer ab.Release() for i := 0; i < 5; i++ { ab.Append(float32(i)) } a := ab.NewArray() defer a.Release() u64, err := anyarrow.NewUint64(a) if err != nil { panic(err) } for i := 0; i < 5; i++ { fmt.Println(u64.Value(i)) } f32, err := anyarrow.NewFloat32(a) if !f32.IsDirect() { panic("f32 is not direct") } for i := 0; i < 5; i++ { fmt.Println(f32.Value(i)) } }
Output: 0 1 2 3 4 0 1 2 3 4
Example (Dictionary) ¶
package main import ( "fmt" "github.com/fardream/anyarrow" "github.com/apache/arrow/go/v15/arrow" "github.com/apache/arrow/go/v15/arrow/array" "github.com/apache/arrow/go/v15/arrow/memory" ) func main() { mem := memory.NewGoAllocator() dicttype := arrow.DictionaryType{ ValueType: &arrow.Int64Type{}, IndexType: &arrow.Int8Type{}, } ab := array.NewDictionaryBuilder(mem, &dicttype) defer ab.Release() abb, ok := ab.(*array.Int64DictionaryBuilder) if !ok { panic("not correct dictionary builder type") } abb.Append(1024) abb.Append(1023) abb.Append(1024) abb.Append(1024) abb.Append(1023) dictarray := abb.NewArray() defer dictarray.Release() int64array, err := anyarrow.NewInt64(dictarray) if err != nil { panic(err) } fmt.Printf("len: %d\n", int64array.Len()) for i := 0; i < 5; i++ { fmt.Println(int64array.Value(i)) } dict, ok := dictarray.(*array.Dictionary) if !ok { panic("not a dictionary") } fmt.Printf("dict len: %d", dict.Dictionary().Len()) }
Output: len: 5 1024 1023 1024 1024 1023 dict len: 2
Example (String) ¶
package main import ( "fmt" "github.com/fardream/anyarrow" "github.com/apache/arrow/go/v15/arrow" "github.com/apache/arrow/go/v15/arrow/array" "github.com/apache/arrow/go/v15/arrow/memory" ) func main() { mem := memory.NewGoAllocator() dicttype := arrow.DictionaryType{ ValueType: &arrow.StringType{}, IndexType: &arrow.Int8Type{}, } ab := array.NewDictionaryBuilder(mem, &dicttype) defer ab.Release() abb, ok := ab.(*array.BinaryDictionaryBuilder) if !ok { panic("not correct dictionary builder type") } abb.AppendString("abc") abb.AppendString("def") abb.AppendString("abc") abb.AppendString("abc") abb.AppendString("def") dictarray := abb.NewArray() defer dictarray.Release() stringarray, err := anyarrow.NewString(dictarray) if err != nil { panic(err) } fmt.Printf("len: %d\n", stringarray.Len()) for i := 0; i < 5; i++ { fmt.Println(stringarray.Value(i)) } dict, ok := dictarray.(*array.Dictionary) if !ok { panic("not a dictionary") } fmt.Printf("dict len: %d", dict.Dictionary().Len()) }
Output: len: 5 abc def abc abc def dict len: 2
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Byte ¶
type Byte struct {
// contains filtered or unexported fields
}
Byte provides convenient access to arrow.Array's element as byte
func (*Byte) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Uint8.
type Float32 ¶
type Float32 struct {
// contains filtered or unexported fields
}
Float32 provides convenient access to arrow.Array's element as float32
func NewFloat32 ¶
NewFloat32 wraps the provided arrow.Array.
func (*Float32) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Float32.
type Float64 ¶
type Float64 struct {
// contains filtered or unexported fields
}
Float64 provides convenient access to arrow.Array's element as float64
func NewFloat64 ¶
NewFloat64 wraps the provided arrow.Array.
func (*Float64) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Float64.
type Int16 ¶
type Int16 struct {
// contains filtered or unexported fields
}
Int16 provides convenient access to arrow.Array's element as int16
func NewInt16 ¶
NewInt16 wraps the provided arrow.Array.
func (*Int16) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Int16.
type Int32 ¶
type Int32 struct {
// contains filtered or unexported fields
}
Int32 provides convenient access to arrow.Array's element as int32
func NewInt32 ¶
NewInt32 wraps the provided arrow.Array.
func (*Int32) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Int32.
type Int64 ¶
type Int64 struct {
// contains filtered or unexported fields
}
Int64 provides convenient access to arrow.Array's element as int64
func NewInt64 ¶
NewInt64 wraps the provided arrow.Array.
func (*Int64) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Int64.
type Int8 ¶
type Int8 struct {
// contains filtered or unexported fields
}
Int8 provides convenient access to arrow.Array's element as int8
func (*Int8) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Int8.
type String ¶ added in v1.1.0
type String struct {
// contains filtered or unexported fields
}
String provides convenient access to arrow.Array's element as string
func NewString ¶ added in v1.1.0
NewString wraps the provided arrow.Array.
func (*String) IsDirect ¶ added in v1.1.0
IsDirect indicates if the underlying arrow.Array is an array.String.
type Uint16 ¶
type Uint16 struct {
// contains filtered or unexported fields
}
Uint16 provides convenient access to arrow.Array's element as uint16
func NewUint16 ¶
NewUint16 wraps the provided arrow.Array.
func (*Uint16) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Uint16.
type Uint32 ¶
type Uint32 struct {
// contains filtered or unexported fields
}
Uint32 provides convenient access to arrow.Array's element as uint32
func NewUint32 ¶
NewUint32 wraps the provided arrow.Array.
func (*Uint32) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Uint32.
type Uint64 ¶
type Uint64 struct {
// contains filtered or unexported fields
}
Uint64 provides convenient access to arrow.Array's element as uint64
func NewUint64 ¶
NewUint64 wraps the provided arrow.Array.
func (*Uint64) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Uint64.
type Uint8 ¶
type Uint8 struct {
// contains filtered or unexported fields
}
Uint8 provides convenient access to arrow.Array's element as uint8
func NewUint8 ¶
NewUint8 wraps the provided arrow.Array.
func (*Uint8) IsDirect ¶
IsDirect indicates if the underlying arrow.Array is an array.Uint8.