package kernels
import (
"fmt"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/compute/exec"
"github.com/apache/arrow-go/v18/arrow/internal/debug"
"github.com/apache/arrow-go/v18/arrow/scalar"
)
var (
unsignedIntTypes = []arrow .DataType {
arrow .PrimitiveTypes .Uint8 ,
arrow .PrimitiveTypes .Uint16 ,
arrow .PrimitiveTypes .Uint32 ,
arrow .PrimitiveTypes .Uint64 ,
}
signedIntTypes = []arrow .DataType {
arrow .PrimitiveTypes .Int8 ,
arrow .PrimitiveTypes .Int16 ,
arrow .PrimitiveTypes .Int32 ,
arrow .PrimitiveTypes .Int64 ,
}
intTypes = append (unsignedIntTypes , signedIntTypes ...)
floatingTypes = []arrow .DataType {
arrow .PrimitiveTypes .Float32 ,
arrow .PrimitiveTypes .Float64 ,
}
numericTypes = append (intTypes , floatingTypes ...)
baseBinaryTypes = []arrow .DataType {
arrow .BinaryTypes .Binary ,
arrow .BinaryTypes .LargeBinary ,
arrow .BinaryTypes .String ,
arrow .BinaryTypes .LargeString }
primitiveTypes = append (append ([]arrow .DataType {arrow .Null ,
arrow .FixedWidthTypes .Date32 , arrow .FixedWidthTypes .Date64 },
numericTypes ...), baseBinaryTypes ...)
)
type CompareOperator int8
const (
CmpEQ CompareOperator = iota
CmpNE
CmpGT
CmpGE
CmpLT
CmpLE
)
type simpleBinaryKernel interface {
Call(*exec .KernelCtx , *exec .ArraySpan , *exec .ArraySpan , *exec .ExecResult ) error
CallScalarLeft(*exec .KernelCtx , scalar .Scalar , *exec .ArraySpan , *exec .ExecResult ) error
}
type commutativeBinaryKernel[T simpleBinaryKernel ] struct {}
func (commutativeBinaryKernel [T ]) CallScalarRight (ctx *exec .KernelCtx , left *exec .ArraySpan , right scalar .Scalar , out *exec .ExecResult ) error {
var t T
return t .CallScalarLeft (ctx , right , left , out )
}
type SimpleBinaryKernel interface {
simpleBinaryKernel
CallScalarRight (*exec .KernelCtx , *exec .ArraySpan , scalar .Scalar , *exec .ExecResult ) error
}
func SimpleBinary [K SimpleBinaryKernel ](ctx *exec .KernelCtx , batch *exec .ExecSpan , out *exec .ExecResult ) error {
if batch .Len == 0 {
return nil
}
var k K
if batch .Values [0 ].IsArray () {
if batch .Values [1 ].IsArray () {
return k .Call (ctx , &batch .Values [0 ].Array , &batch .Values [1 ].Array , out )
}
return k .CallScalarRight (ctx , &batch .Values [0 ].Array , batch .Values [1 ].Scalar , out )
}
if batch .Values [1 ].IsArray () {
return k .CallScalarLeft (ctx , batch .Values [0 ].Scalar , &batch .Values [1 ].Array , out )
}
debug .Assert (false , "should be unreachable" )
return fmt .Errorf ("%w: should be unreachable" , arrow .ErrInvalid )
}
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 .