archery

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2025 License: MIT Imports: 8 Imported by: 0

README

Archery: Apache Arrow Compute Library for Go

Archery is a Go library that provides a user-friendly interface to the Apache Arrow compute package. It simplifies working with Arrow arrays and compute operations by providing a set of helper functions for common tasks.

Features

  • Arithmetic Operations: Add, subtract, multiply, divide, and more operations on Arrow arrays.
  • Filtering Operations: Filter arrays based on various conditions like greater than, less than, equal to, etc.
  • Aggregation Operations: Calculate sum, mean, min, max, standard deviation, and other statistics on Arrow arrays.
  • Sorting Operations: Sort arrays, get sort indices, find nth elements, and calculate ranks.
  • Comparison Operations: Compare arrays for equality, inequality, greater than, less than, etc.

Installation

go get github.com/TFMV/archery

Available Functions

Arithmetic Functions
  • add, subtract, multiply, divide
  • power, sqrt, sign, negate, abs
Filtering Functions
  • FilterByMask, FilterGreaterThan, FilterLessThan
  • FilterEqual, FilterNotEqual, FilterBetween
  • FilterIsMultipleOf, FilterIn, FilterNotNull
Aggregation Functions
  • Sum, Mean, Min, Max, MinMax
  • Count, CountNonNull, Variance, StandardDeviation
  • Quantile, Median
Sorting Functions
  • Sort, SortIndicesWithOrder, TakeWithIndices
  • NthElement, Rank, UniqueValues
Comparison Functions
  • equal, not_equal, greater, less
  • greater_equal, less_equal, and, or, not

License

MIT

Documentation

Overview

Package arrow provides utility functions for working with the Apache Arrow compute package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsoluteValue

func AbsoluteValue(ctx context.Context, arr arrow.Array) (arrow.Array, error)

AbsoluteValue computes the absolute value of each element in the array. Returns the resulting array and any error encountered.

func Acos

func Acos(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Acos computes the arccosine of each element in the array. Returns the resulting array and any error encountered.

func Add

func Add(ctx context.Context, left, right arrow.Array) (arrow.Array, error)

Add performs element-wise addition of two arrays. Returns the resulting array and any error encountered.

func AddScalar

func AddScalar(ctx context.Context, arr arrow.Array, val interface{}) (arrow.Array, error)

AddScalar performs element-wise addition of an array and a scalar. Returns the resulting array and any error encountered.

func Asin

func Asin(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Asin computes the arcsine of each element in the array. Returns the resulting array and any error encountered.

func Atan

func Atan(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Atan computes the arctangent of each element in the array. Returns the resulting array and any error encountered.

func Cos

func Cos(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Cos computes the cosine of each element in the array. Returns the resulting array and any error encountered.

func Count

func Count(ctx context.Context, arr arrow.Array) (int64, error)

Count counts the number of elements in an array. Returns the count as an int64 and any error encountered.

func CountNonNull

func CountNonNull(ctx context.Context, arr arrow.Array) (int64, error)

CountNonNull counts the number of non-null elements in an array. Returns the count as an int64 and any error encountered.

func CreateBooleanArray

func CreateBooleanArray(mem memory.Allocator, values []bool, validity []bool) *array.Boolean

CreateBooleanArray creates a BooleanArray with the given values and validity.

func CreateBooleanMask

func CreateBooleanMask(ctx context.Context, arr arrow.Array, fn func(int) bool) *array.Boolean

CreateBooleanMask creates a boolean mask from a function that evaluates each element. The function should take an index and return a boolean value. Returns the boolean mask array.

func CreateFloat64Array

func CreateFloat64Array(mem memory.Allocator, values []float64, validity []bool) *array.Float64

CreateFloat64Array creates a Float64Array with the given values and validity.

func CreateInt64Array

func CreateInt64Array(mem memory.Allocator, values []int64, validity []bool) *array.Int64

CreateInt64Array creates an Int64Array with the given values and validity.

func CreateStringArray

func CreateStringArray(mem memory.Allocator, values []string, validity []bool) *array.String

CreateStringArray creates a StringArray with the given values and validity.

func DatumToArray

func DatumToArray(datum compute.Datum) arrow.Array

DatumToArray converts a compute.Datum to an arrow.Array. Returns nil if the conversion is not possible.

func DatumToBooleanArray

func DatumToBooleanArray(datum compute.Datum) *array.Boolean

DatumToBooleanArray converts a compute.Datum to an *array.Boolean. Returns nil if the conversion is not possible.

func DatumToFloat64Array

func DatumToFloat64Array(datum compute.Datum) *array.Float64

DatumToFloat64Array converts a compute.Datum to an *array.Float64. Returns nil if the conversion is not possible.

func DatumToInt64Array

func DatumToInt64Array(datum compute.Datum) *array.Int64

DatumToInt64Array converts a compute.Datum to an *array.Int64. Returns nil if the conversion is not possible.

func DatumToStringArray

func DatumToStringArray(datum compute.Datum) *array.String

DatumToStringArray converts a compute.Datum to an *array.String. Returns nil if the conversion is not possible.

func Divide

func Divide(ctx context.Context, left, right arrow.Array) (arrow.Array, error)

Divide performs element-wise division of two arrays. Returns the resulting array and any error encountered.

func DivideScalar

func DivideScalar(ctx context.Context, arr arrow.Array, val interface{}) (arrow.Array, error)

DivideScalar performs element-wise division of an array and a scalar. Returns the resulting array and any error encountered.

func ExtractBooleanValues

func ExtractBooleanValues(arr *array.Boolean) []*bool

ExtractBooleanValues extracts the values from a BooleanArray into a slice. Null values are represented as nil in the returned slice.

func ExtractFloat64Values

func ExtractFloat64Values(arr *array.Float64) []*float64

ExtractFloat64Values extracts the values from a Float64Array into a slice. Null values are represented as nil in the returned slice.

func ExtractInt64Values

func ExtractInt64Values(arr *array.Int64) []*int64

ExtractInt64Values extracts the values from an Int64Array into a slice. Null values are represented as nil in the returned slice.

func ExtractStringValues

func ExtractStringValues(arr *array.String) []*string

ExtractStringValues extracts the values from a StringArray into a slice. Null values are represented as nil in the returned slice.

func FilterBetween

func FilterBetween(ctx context.Context, arr arrow.Array, lower, upper interface{}) (arrow.Array, error)

FilterBetween filters an array to include only elements between the specified lower and upper bounds (inclusive). Returns the filtered array and any error encountered.

func FilterByMask

func FilterByMask(ctx context.Context, arr arrow.Array, mask *array.Boolean) (arrow.Array, error)

FilterByMask filters an array using a boolean mask. Returns the filtered array and any error encountered.

func FilterEqual

func FilterEqual(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterEqual filters an array to include only elements equal to the specified value. Returns the filtered array and any error encountered.

func FilterGreaterEqual

func FilterGreaterEqual(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterGreaterEqual filters an array to include only elements greater than or equal to the specified value. Returns the filtered array and any error encountered.

func FilterGreaterThan

func FilterGreaterThan(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterGreaterThan filters an array to include only elements greater than the specified value. Returns the filtered array and any error encountered.

func FilterIn

func FilterIn(ctx context.Context, arr arrow.Array, values arrow.Array) (arrow.Array, error)

FilterIn filters an array to include only elements that are in the specified values array. Returns the filtered array and any error encountered.

func FilterIsMultipleOf

func FilterIsMultipleOf(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterIsMultipleOf filters an array to include only elements that are multiples of the specified value. Returns the filtered array and any error encountered.

func FilterLessEqual

func FilterLessEqual(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterLessEqual filters an array to include only elements less than or equal to the specified value. Returns the filtered array and any error encountered.

func FilterLessThan

func FilterLessThan(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterLessThan filters an array to include only elements less than the specified value. Returns the filtered array and any error encountered.

func FilterNotEqual

func FilterNotEqual(ctx context.Context, arr arrow.Array, value interface{}) (arrow.Array, error)

FilterNotEqual filters an array to include only elements not equal to the specified value. Returns the filtered array and any error encountered.

func FilterNotNull

func FilterNotNull(ctx context.Context, arr arrow.Array) (arrow.Array, error)

FilterNotNull filters an array to include only non-null elements. Returns the filtered array and any error encountered.

func Ln

func Ln(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Ln computes the natural logarithm of each element in the array. Returns the resulting array and any error encountered.

func Log2

func Log2(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Log2 computes the base-2 logarithm of each element in the array. Returns the resulting array and any error encountered.

func Log10

func Log10(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Log10 computes the base-10 logarithm of each element in the array. Returns the resulting array and any error encountered.

func Max

func Max(ctx context.Context, arr arrow.Array) (scalar.Scalar, error)

Max finds the maximum value in an array. Returns the resulting scalar and any error encountered.

func Mean

func Mean(ctx context.Context, arr arrow.Array) (scalar.Scalar, error)

Mean calculates the arithmetic mean of all elements in an array. Returns the resulting scalar and any error encountered.

func Median

func Median(ctx context.Context, arr arrow.Array) (scalar.Scalar, error)

Median calculates the median of the elements in an array. Returns the median value and any error encountered.

func Min

func Min(ctx context.Context, arr arrow.Array) (scalar.Scalar, error)

Min finds the minimum value in an array. Returns the resulting scalar and any error encountered.

func Multiply

func Multiply(ctx context.Context, left, right arrow.Array) (arrow.Array, error)

Multiply performs element-wise multiplication of two arrays. Returns the resulting array and any error encountered.

func MultiplyScalar

func MultiplyScalar(ctx context.Context, arr arrow.Array, val interface{}) (arrow.Array, error)

MultiplyScalar performs element-wise multiplication of an array and a scalar. Returns the resulting array and any error encountered.

func Negate

func Negate(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Negate computes the negation of each element in the array. Returns the resulting array and any error encountered.

func NthElement

func NthElement(ctx context.Context, arr arrow.Array, n int64, order SortOrder) (scalar.Scalar, error)

NthElement returns the nth element of the sorted array. Returns the scalar value and any error encountered.

func Power

func Power(ctx context.Context, base, exponent arrow.Array) (arrow.Array, error)

Power raises each element in the base array to the power of the corresponding element in the exponent array. Returns the resulting array and any error encountered.

func PowerScalar

func PowerScalar(ctx context.Context, arr arrow.Array, exponent interface{}) (arrow.Array, error)

PowerScalar raises each element in the array to the power of the scalar value. Returns the resulting array and any error encountered.

func Quantile

func Quantile(ctx context.Context, arr arrow.Array, q float64) (scalar.Scalar, error)

Quantile calculates the quantile of the elements in an array. The quantile parameter should be between 0 and 1. Returns the quantile value and any error encountered.

func Rank

func Rank(ctx context.Context, arr arrow.Array, order SortOrder) (arrow.Array, error)

Rank returns an array with the rank of each element in the input array. Returns a new Int64Array with the ranks and any error encountered.

func Round

func Round(ctx context.Context, arr arrow.Array, nDigits int64) (arrow.Array, error)

Round rounds each element in the array to the specified number of decimal places. Returns the resulting array and any error encountered.

func Sign

func Sign(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Sign returns the sign of each element in the array (-1, 0, or 1). Returns the resulting array and any error encountered.

func Sin

func Sin(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Sin computes the sine of each element in the array. Returns the resulting array and any error encountered.

func Sort

func Sort(ctx context.Context, arr arrow.Array, order SortOrder) (arrow.Array, error)

Sort returns a new array with the elements sorted. Returns a new array of the same type as the input and any error encountered.

func SortIndicesWithOrder

func SortIndicesWithOrder(ctx context.Context, arr arrow.Array, order SortOrder) (*array.Int64, error)

SortIndicesWithOrder returns the indices that would sort the array according to the specified order. Returns an Int64Array containing the indices and any error encountered.

func StandardDeviation

func StandardDeviation(ctx context.Context, arr arrow.Array) (float64, error)

StandardDeviation calculates the standard deviation of the elements in an array. Returns the standard deviation as a float64 and any error encountered.

func Subtract

func Subtract(ctx context.Context, left, right arrow.Array) (arrow.Array, error)

Subtract performs element-wise subtraction of two arrays. Returns the resulting array and any error encountered.

func SubtractScalar

func SubtractScalar(ctx context.Context, arr arrow.Array, val interface{}) (arrow.Array, error)

SubtractScalar performs element-wise subtraction of an array and a scalar. Returns the resulting array and any error encountered.

func Sum

func Sum(ctx context.Context, arr arrow.Array) (scalar.Scalar, error)

Sum calculates the sum of all elements in an array. Returns the resulting scalar and any error encountered.

func Take

func Take(ctx context.Context, arr arrow.Array, indices arrow.Array) (arrow.Array, error)

Take selects elements from an array based on the provided indices. Returns the resulting array and any error encountered.

func TakeWithIndices

func TakeWithIndices(ctx context.Context, arr arrow.Array, indices *array.Int64) (arrow.Array, error)

TakeWithIndices returns a new array with elements taken from the input array at the specified indices. Returns a new array of the same type as the input and any error encountered.

func Tan

func Tan(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Tan computes the tangent of each element in the array. Returns the resulting array and any error encountered.

func Unique

func Unique(ctx context.Context, arr arrow.Array) (arrow.Array, error)

Unique returns the unique values in an array. Returns the resulting array and any error encountered.

func UniqueValues

func UniqueValues(ctx context.Context, arr arrow.Array) (arrow.Array, error)

UniqueValues returns a new array with duplicate elements removed. Returns a new array of the same type as the input and any error encountered.

func Variance

func Variance(ctx context.Context, arr arrow.Array) (float64, error)

Variance calculates the variance of the elements in an array. Returns the variance as a float64 and any error encountered.

Types

type MinMaxResult

type MinMaxResult struct {
	Min scalar.Scalar
	Max scalar.Scalar
}

MinMaxResult contains the min and max scalars.

func MinMax

func MinMax(ctx context.Context, arr arrow.Array) (*MinMaxResult, error)

MinMax finds both the minimum and maximum values in an array. Returns a struct containing the min and max scalars, and any error encountered.

type QuantileOpts

type QuantileOpts struct {
	Interpolation string
	Quantiles     []float64
}

QuantileOpts implements compute.FunctionOptions for the quantile function

func (*QuantileOpts) TypeName

func (o *QuantileOpts) TypeName() string

TypeName implements the compute.FunctionOptions interface

type SortIndicesOptions

type SortIndicesOptions struct {
	Descending bool
}

SortIndicesOptions implements compute.FunctionOptions for the sort_indices function

func (*SortIndicesOptions) TypeName

func (o *SortIndicesOptions) TypeName() string

TypeName implements the compute.FunctionOptions interface

type SortOrder

type SortOrder int

SortOrder represents the order in which elements should be sorted.

const (
	// Ascending order (smallest to largest)
	Ascending SortOrder = iota
	// Descending order (largest to smallest)
	Descending
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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