package kernels
import (
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/compute/exec"
)
type CastOptions struct {
ToType arrow .DataType `compute:"to_type"`
AllowIntOverflow bool `compute:"allow_int_overflow"`
AllowTimeTruncate bool `compute:"allow_time_truncate"`
AllowTimeOverflow bool `compute:"allow_time_overflow"`
AllowDecimalTruncate bool `compute:"allow_decimal_truncate"`
AllowFloatTruncate bool `compute:"allow_float_truncate"`
AllowInvalidUtf8 bool `compute:"allow_invalid_utf8"`
}
func (CastOptions ) TypeName () string { return "CastOptions" }
type CastState = CastOptions
func ZeroCopyCastExec (_ *exec .KernelCtx , batch *exec .ExecSpan , out *exec .ExecResult ) error {
out .Release ()
dt := out .Type
*out = batch .Values [0 ].Array
out .Type = dt
return nil
}
func recursiveSetSelfAlloc(arr *exec .ArraySpan ) {
for i := range arr .Buffers {
if len (arr .Buffers [i ].Buf ) > 0 {
arr .Buffers [i ].SelfAlloc = true
if arr .Buffers [i ].Owner != nil {
arr .Buffers [i ].Owner .Retain ()
}
}
}
for i := range arr .Children {
recursiveSetSelfAlloc (&arr .Children [i ])
}
}
func CastFromNull (ctx *exec .KernelCtx , batch *exec .ExecSpan , out *exec .ExecResult ) error {
arr := array .MakeArrayOfNull (exec .GetAllocator (ctx .Ctx ), out .Type , int (batch .Len ))
defer arr .Release ()
out .SetMembers (arr .Data ())
recursiveSetSelfAlloc (out )
return nil
}
func OutputAllNull (_ *exec .KernelCtx , batch *exec .ExecSpan , out *exec .ExecResult ) error {
out .Nulls = batch .Len
return nil
}
func CanCastFromDict (id arrow .Type ) bool {
return arrow .IsPrimitive (id ) || arrow .IsBaseBinary (id ) || arrow .IsFixedSizeBinary (id )
}
func GetZeroCastKernel (inID arrow .Type , inType exec .InputType , out exec .OutputType ) exec .ScalarKernel {
k := exec .NewScalarKernel ([]exec .InputType {inType }, out , ZeroCopyCastExec , nil )
k .NullHandling = exec .NullComputedNoPrealloc
k .MemAlloc = exec .MemNoPrealloc
return k
}
func GetCommonCastKernels (outID arrow .Type , outType exec .OutputType ) (out []exec .ScalarKernel ) {
out = make ([]exec .ScalarKernel , 0 , 2 )
kernel := exec .NewScalarKernel ([]exec .InputType {exec .NewExactInput (arrow .Null )}, outType ,
CastFromNull , nil )
kernel .NullHandling = exec .NullComputedNoPrealloc
kernel .MemAlloc = exec .MemNoPrealloc
out = append (out , kernel )
return
}
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 .