anyarrow

package module
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 3 Imported by: 0

README

anyarrow

Go Reference

anyarrow provides wrapper types for arrow.Array, so users can simply create a new Int8 from an arrow.Array and this library will handle the conversion.

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 NewByte

func NewByte(a arrow.Array) (*Byte, error)

NewByte wraps the provided arrow.Array.

func (*Byte) IsDirect

func (a *Byte) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Uint8.

func (*Byte) Value

func (a *Byte) Value(i int) byte

Value retrieves the element at index i as byte

type Float32

type Float32 struct {
	// contains filtered or unexported fields
}

Float32 provides convenient access to arrow.Array's element as float32

func NewFloat32

func NewFloat32(a arrow.Array) (*Float32, error)

NewFloat32 wraps the provided arrow.Array.

func (*Float32) IsDirect

func (a *Float32) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Float32.

func (*Float32) Value

func (a *Float32) Value(i int) float32

Value retrieves the element at index i as float32

type Float64

type Float64 struct {
	// contains filtered or unexported fields
}

Float64 provides convenient access to arrow.Array's element as float64

func NewFloat64

func NewFloat64(a arrow.Array) (*Float64, error)

NewFloat64 wraps the provided arrow.Array.

func (*Float64) IsDirect

func (a *Float64) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Float64.

func (*Float64) Value

func (a *Float64) Value(i int) float64

Value retrieves the element at index i as float64

type Int16

type Int16 struct {
	// contains filtered or unexported fields
}

Int16 provides convenient access to arrow.Array's element as int16

func NewInt16

func NewInt16(a arrow.Array) (*Int16, error)

NewInt16 wraps the provided arrow.Array.

func (*Int16) IsDirect

func (a *Int16) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Int16.

func (*Int16) Value

func (a *Int16) Value(i int) int16

Value retrieves the element at index i as int16

type Int32

type Int32 struct {
	// contains filtered or unexported fields
}

Int32 provides convenient access to arrow.Array's element as int32

func NewInt32

func NewInt32(a arrow.Array) (*Int32, error)

NewInt32 wraps the provided arrow.Array.

func (*Int32) IsDirect

func (a *Int32) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Int32.

func (*Int32) Value

func (a *Int32) Value(i int) int32

Value retrieves the element at index i as int32

type Int64

type Int64 struct {
	// contains filtered or unexported fields
}

Int64 provides convenient access to arrow.Array's element as int64

func NewInt64

func NewInt64(a arrow.Array) (*Int64, error)

NewInt64 wraps the provided arrow.Array.

func (*Int64) IsDirect

func (a *Int64) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Int64.

func (*Int64) Value

func (a *Int64) Value(i int) int64

Value retrieves the element at index i as int64

type Int8

type Int8 struct {
	// contains filtered or unexported fields
}

Int8 provides convenient access to arrow.Array's element as int8

func NewInt8

func NewInt8(a arrow.Array) (*Int8, error)

NewInt8 wraps the provided arrow.Array.

func (*Int8) IsDirect

func (a *Int8) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Int8.

func (*Int8) Value

func (a *Int8) Value(i int) int8

Value retrieves the element at index i as 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

func NewString(a arrow.Array) (*String, error)

NewString wraps the provided arrow.Array.

func (*String) IsDirect added in v1.1.0

func (a *String) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.String.

func (*String) Value added in v1.1.0

func (a *String) Value(i int) string

Value retrieves the element at index i as string

type Uint16

type Uint16 struct {
	// contains filtered or unexported fields
}

Uint16 provides convenient access to arrow.Array's element as uint16

func NewUint16

func NewUint16(a arrow.Array) (*Uint16, error)

NewUint16 wraps the provided arrow.Array.

func (*Uint16) IsDirect

func (a *Uint16) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Uint16.

func (*Uint16) Value

func (a *Uint16) Value(i int) uint16

Value retrieves the element at index i as uint16

type Uint32

type Uint32 struct {
	// contains filtered or unexported fields
}

Uint32 provides convenient access to arrow.Array's element as uint32

func NewUint32

func NewUint32(a arrow.Array) (*Uint32, error)

NewUint32 wraps the provided arrow.Array.

func (*Uint32) IsDirect

func (a *Uint32) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Uint32.

func (*Uint32) Value

func (a *Uint32) Value(i int) uint32

Value retrieves the element at index i as uint32

type Uint64

type Uint64 struct {
	// contains filtered or unexported fields
}

Uint64 provides convenient access to arrow.Array's element as uint64

func NewUint64

func NewUint64(a arrow.Array) (*Uint64, error)

NewUint64 wraps the provided arrow.Array.

func (*Uint64) IsDirect

func (a *Uint64) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Uint64.

func (*Uint64) Value

func (a *Uint64) Value(i int) uint64

Value retrieves the element at index i as uint64

type Uint8

type Uint8 struct {
	// contains filtered or unexported fields
}

Uint8 provides convenient access to arrow.Array's element as uint8

func NewUint8

func NewUint8(a arrow.Array) (*Uint8, error)

NewUint8 wraps the provided arrow.Array.

func (*Uint8) IsDirect

func (a *Uint8) IsDirect() bool

IsDirect indicates if the underlying arrow.Array is an array.Uint8.

func (*Uint8) Value

func (a *Uint8) Value(i int) uint8

Value retrieves the element at index i as uint8

Directories

Path Synopsis
cmd
gen

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL