archery

package module
v0.3.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: 9 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.
  • Record Operations: Apply array operations to Arrow Records, including filtering, sorting, aggregation, and grouping.

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
Record Operations
  • FilterRecordByMask, FilterRecordRows, FilterRecordByColumn: Filter records based on conditions
  • FilterRecordGreaterThan, FilterRecordLessThan, FilterRecordEqual, FilterRecordBetween: Filter records with common conditions
  • SortRecordByColumn: Sort records by a specified column
  • AggregateRecordColumn: Apply aggregation functions to columns
  • SumRecordColumn, MeanRecordColumn, MinRecordColumn, MaxRecordColumn: Common aggregation operations
  • GroupByRecord: Group records by one or more columns and apply aggregation functions
  • GetRecordColumn: Get a column array by name
RecordWrapper (Alternative Approach)
  • RecordWrapper: A wrapper for Arrow Records that provides methods to apply array operations to records
  • FilterByMask, FilterRows, FilterRowsByColumn: Filter records based on conditions
  • SortRecord: Sort records by a specified column
  • AggregateColumn: Apply aggregation functions to columns
  • GroupBy: Group records by one or more columns and apply aggregation functions

Usage Examples

Working with Arrays
// Create an array
builder := array.NewFloat64Builder(memory.DefaultAllocator)
builder.AppendValues([]float64{1.0, 2.0, 3.0, 4.0, 5.0}, nil)
arr := builder.NewFloat64Array()
defer arr.Release()

// Perform arithmetic operation
ctx := context.Background()
result, err := archery.Add(ctx, arr, arr)
if err != nil {
    log.Fatal(err)
}
defer result.Release()

// Filter array
filtered, err := archery.FilterGreaterThan(ctx, arr, 3.0)
if err != nil {
    log.Fatal(err)
}
defer filtered.Release()

// Calculate aggregation
sum, err := archery.Sum(ctx, arr)
if err != nil {
    log.Fatal(err)
}
Working with Records (Package-Level Functions)
// Create a record
schema := arrow.NewSchema(
    []arrow.Field{
        {Name: "id", Type: arrow.PrimitiveTypes.Int64},
        {Name: "name", Type: arrow.BinaryTypes.String},
        {Name: "score", Type: arrow.PrimitiveTypes.Float64},
    },
    nil,
)

// Create arrays for the record
idArray := ... // Int64Array
nameArray := ... // StringArray
scoreArray := ... // Float64Array

// Create the record
record := array.NewRecord(schema, []arrow.Array{idArray, nameArray, scoreArray}, 5)
defer record.Release()

// Memory allocator
mem := memory.DefaultAllocator

// Filter records where score > 80
ctx := context.Background()
filtered, err := archery.FilterRecordGreaterThan(ctx, record, "score", 80.0, mem)
if err != nil {
    log.Fatal(err)
}
defer filtered.Release()

// Sort records by score in descending order
sorted, err := archery.SortRecordByColumn(ctx, record, "score", archery.Descending, mem)
if err != nil {
    log.Fatal(err)
}
defer sorted.Release()

// Calculate mean score
mean, err := archery.MeanRecordColumn(ctx, record, "score", mem)
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Mean score: %.2f\n", mean)

// Group by category and calculate mean scores
groupByResult, err := archery.GroupByRecord(ctx, record, []string{"category"}, map[string]func(context.Context, arrow.Array) (interface{}, error){
    "score": archery.MeanAggregator(),
}, mem)
if err != nil {
    log.Fatal(err)
}
defer groupByResult.Release()

// Convert the result to a record
groupedRecord := groupByResult.ToRecord(mem)
defer groupedRecord.Release()
Working with Records (RecordWrapper)
// Create a record
record := array.NewRecord(schema, []arrow.Array{idArray, nameArray, scoreArray}, 5)
defer record.Release()

// Create a RecordWrapper
wrapper := archery.NewRecordWrapper(record, memory.DefaultAllocator)

// Filter records where score > 80
ctx := context.Background()
filtered, err := wrapper.FilterRowsByColumn(ctx, "score", archery.GreaterThan(80.0))
if err != nil {
    log.Fatal(err)
}
defer filtered.Release()

// Sort records by score in descending order
sorted, err := wrapper.SortRecord(ctx, "score", archery.Descending)
if err != nil {
    log.Fatal(err)
}
defer sorted.Release()

// Calculate mean score
mean, err := wrapper.AggregateColumn(ctx, "score", archery.MeanAggregator())
if err != nil {
    log.Fatal(err)
}
fmt.Printf("Mean score: %.2f\n", mean)

// Group by category and calculate mean scores
groupByResult, err := wrapper.GroupBy(ctx, []string{"category"}, map[string]func(context.Context, arrow.Array) (interface{}, error){
    "score": archery.MeanAggregator(),
})
if err != nil {
    log.Fatal(err)
}
defer groupByResult.Release()

// Convert the result to a record
groupedRecord := groupByResult.ToRecord(memory.DefaultAllocator)
defer groupedRecord.Release()

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 AggregateRecordColumn added in v0.3.0

func AggregateRecordColumn(ctx context.Context, record arrow.Record, columnName string,
	aggregator func(context.Context, arrow.Array) (interface{}, error), mem memory.Allocator) (interface{}, error)

AggregateRecordColumn applies an aggregation function to a column in a record The aggregation function should take an array and return a scalar value

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 Between added in v0.2.0

func Between(lower, upper interface{}) func(arrow.Array, int) bool

Between returns a condition function that checks if a value is between the specified lower and upper bounds (inclusive)

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 Equal added in v0.2.0

func Equal(value interface{}) func(arrow.Array, int) bool

Equal returns a condition function that checks if a value is equal to the specified value

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 FilterRecordBetween added in v0.3.0

func FilterRecordBetween(ctx context.Context, record arrow.Record, columnName string,
	lower, upper interface{}, mem memory.Allocator) (arrow.Record, error)

FilterRecordBetween filters a record to include only rows where the specified column is between lower and upper (inclusive)

func FilterRecordByColumn added in v0.3.0

func FilterRecordByColumn(ctx context.Context, record arrow.Record, columnName string,
	condition func(arrow.Array, int) bool, mem memory.Allocator) (arrow.Record, error)

FilterRecordByColumn filters a record based on a condition applied to a specific column Returns a new record with only the rows where the condition is true

func FilterRecordByMask added in v0.3.0

func FilterRecordByMask(ctx context.Context, record arrow.Record, mask *array.Boolean, mem memory.Allocator) (arrow.Record, error)

FilterRecordByMask filters a record using a boolean mask Returns a new record with only the rows where the mask is true

func FilterRecordEqual added in v0.3.0

func FilterRecordEqual(ctx context.Context, record arrow.Record, columnName string,
	value interface{}, mem memory.Allocator) (arrow.Record, error)

FilterRecordEqual filters a record to include only rows where the specified column equals the value

func FilterRecordGreaterThan added in v0.3.0

func FilterRecordGreaterThan(ctx context.Context, record arrow.Record, columnName string,
	value interface{}, mem memory.Allocator) (arrow.Record, error)

FilterRecordGreaterThan filters a record to include only rows where the specified column is greater than the value

func FilterRecordLessThan added in v0.3.0

func FilterRecordLessThan(ctx context.Context, record arrow.Record, columnName string,
	value interface{}, mem memory.Allocator) (arrow.Record, error)

FilterRecordLessThan filters a record to include only rows where the specified column is less than the value

func FilterRecordRows added in v0.3.0

func FilterRecordRows(ctx context.Context, record arrow.Record, predicate func(int) bool, mem memory.Allocator) (arrow.Record, error)

FilterRecordRows filters a record based on a predicate function The predicate function takes a row index and returns true if the row should be included

func GetRecordColumn added in v0.3.0

func GetRecordColumn(record arrow.Record, columnName string) (arrow.Array, error)

GetRecordColumn returns the array for the specified column name

func GreaterThan added in v0.2.0

func GreaterThan(value interface{}) func(arrow.Array, int) bool

GreaterThan returns a condition function that checks if a value is greater than the specified value

func LessThan added in v0.2.0

func LessThan(value interface{}) func(arrow.Array, int) bool

LessThan returns a condition function that checks if a value is less than the specified value

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 MaxAggregator added in v0.2.0

func MaxAggregator() func(context.Context, arrow.Array) (interface{}, error)

MaxAggregator returns an aggregator function that finds the maximum value in a column

func MaxRecordColumn added in v0.3.0

func MaxRecordColumn(ctx context.Context, record arrow.Record, columnName string, mem memory.Allocator) (interface{}, error)

MaxRecordColumn finds the maximum value in the specified column

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 MeanAggregator added in v0.2.0

func MeanAggregator() func(context.Context, arrow.Array) (interface{}, error)

MeanAggregator returns an aggregator function that calculates the mean of a column

func MeanRecordColumn added in v0.3.0

func MeanRecordColumn(ctx context.Context, record arrow.Record, columnName string, mem memory.Allocator) (float64, error)

MeanRecordColumn calculates the mean of values in the specified column

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 MinAggregator added in v0.2.0

func MinAggregator() func(context.Context, arrow.Array) (interface{}, error)

MinAggregator returns an aggregator function that finds the minimum value in a column

func MinRecordColumn added in v0.3.0

func MinRecordColumn(ctx context.Context, record arrow.Record, columnName string, mem memory.Allocator) (interface{}, error)

MinRecordColumn finds the minimum value in the specified column

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 SortRecordByColumn added in v0.3.0

func SortRecordByColumn(ctx context.Context, record arrow.Record, columnName string,
	order SortOrder, mem memory.Allocator) (arrow.Record, error)

SortRecordByColumn sorts a record by the specified column Returns a new record with rows sorted according to the column values

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 SumAggregator added in v0.2.0

func SumAggregator() func(context.Context, arrow.Array) (interface{}, error)

SumAggregator returns an aggregator function that calculates the sum of a column

func SumRecordColumn added in v0.3.0

func SumRecordColumn(ctx context.Context, record arrow.Record, columnName string, mem memory.Allocator) (interface{}, error)

SumRecordColumn calculates the sum of values in the specified column

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 GroupByResult added in v0.2.0

type GroupByResult struct {
	Keys       map[string]arrow.Array
	Aggregates map[string]arrow.Array
}

GroupBy groups a record by one or more columns and applies aggregation functions to other columns Returns a new record with one row per group and the aggregated values

func GroupByRecord added in v0.3.0

func GroupByRecord(ctx context.Context, record arrow.Record, keyColumns []string,
	aggregations map[string]func(context.Context, arrow.Array) (interface{}, error), mem memory.Allocator) (*GroupByResult, error)

GroupByRecord groups a record by the specified key columns and applies aggregation functions to the value columns

func (*GroupByResult) Release added in v0.2.0

func (gr *GroupByResult) Release()

Release releases all arrays in the GroupByResult

func (*GroupByResult) ToRecord added in v0.2.0

func (gr *GroupByResult) ToRecord(mem memory.Allocator) arrow.Record

ToRecord converts a GroupByResult to a Record

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 RecordWrapper added in v0.2.0

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

RecordWrapper provides methods to apply array operations to Arrow Records

func NewRecordWrapper added in v0.2.0

func NewRecordWrapper(record arrow.Record, mem memory.Allocator) *RecordWrapper

NewRecordWrapper creates a new RecordWrapper for the given record

func (*RecordWrapper) AggregateColumn added in v0.2.0

func (rw *RecordWrapper) AggregateColumn(ctx context.Context, columnName string,
	aggregator func(context.Context, arrow.Array) (interface{}, error)) (interface{}, error)

AggregateColumn applies an aggregation function to a column The aggregation function should take an array and return a scalar value

func (*RecordWrapper) Column added in v0.2.0

func (rw *RecordWrapper) Column(name string) (arrow.Array, error)

Column returns the array for the specified column name

func (*RecordWrapper) ColumnByIndex added in v0.2.0

func (rw *RecordWrapper) ColumnByIndex(i int) (arrow.Array, error)

ColumnByIndex returns the array for the specified column index

func (*RecordWrapper) ColumnNames added in v0.2.0

func (rw *RecordWrapper) ColumnNames() []string

ColumnNames returns the names of all columns in the record

func (*RecordWrapper) FilterByMask added in v0.2.0

func (rw *RecordWrapper) FilterByMask(ctx context.Context, mask *array.Boolean) (arrow.Record, error)

FilterByMask filters a record using a boolean mask Returns a new record with only the rows where the mask is true

func (*RecordWrapper) FilterRows added in v0.2.0

func (rw *RecordWrapper) FilterRows(ctx context.Context, predicate func(int) bool) (arrow.Record, error)

FilterRows filters a record based on a predicate function The predicate function takes a row index and returns true if the row should be included

func (*RecordWrapper) FilterRowsByColumn added in v0.2.0

func (rw *RecordWrapper) FilterRowsByColumn(ctx context.Context, columnName string, condition func(arrow.Array, int) bool) (arrow.Record, error)

FilterRowsByColumn filters a record based on a condition applied to a specific column Returns a new record with only the rows where the condition is true

func (*RecordWrapper) GroupBy added in v0.2.0

func (rw *RecordWrapper) GroupBy(ctx context.Context, keyColumns []string,
	aggregations map[string]func(context.Context, arrow.Array) (interface{}, error)) (*GroupByResult, error)

GroupBy groups a record by the specified key columns and applies aggregation functions to the value columns

func (*RecordWrapper) Record added in v0.2.0

func (rw *RecordWrapper) Record() arrow.Record

Record returns the underlying Arrow Record

func (*RecordWrapper) SortRecord added in v0.2.0

func (rw *RecordWrapper) SortRecord(ctx context.Context, columnName string, order SortOrder) (arrow.Record, error)

SortRecord sorts a record by the specified column Returns a new record with rows sorted according to the column values

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
examples
array command
record command

Jump to

Keyboard shortcuts

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