zeroshade commented on code in PR #13974:
URL: https://github.com/apache/arrow/pull/13974#discussion_r956300589


##########
go/arrow/compute/internal/kernels/helpers.go:
##########
@@ -0,0 +1,119 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package kernels
+
+import (
+       "github.com/apache/arrow/go/v10/arrow/bitutil"
+       "github.com/apache/arrow/go/v10/arrow/compute/internal/exec"
+       "github.com/apache/arrow/go/v10/internal/bitutils"
+)
+
+// ScalarUnary returns a kernel for performing a unary operation on
+// FixedWidth types which is implemented using the passed in function
+// which will receive a slice containing the raw input data along with
+// a slice to populate for the output data.
+//
+// Note that bool is not included in exec.FixedWidthTypes since it is
+// represented as a bitmap, not as a slice of bool.
+func ScalarUnary[OutT, Arg0T exec.FixedWidthTypes](op func(*exec.KernelCtx, 
[]Arg0T, []OutT) error) exec.ArrayKernelExec {
+       return func(ctx *exec.KernelCtx, in *exec.ExecSpan, out 
*exec.ExecResult) error {
+               arg0 := in.Values[0].Array
+               inData := exec.GetSpanValues[Arg0T](&arg0, 1)
+               outData := exec.GetSpanValues[OutT](out, 1)
+               return op(ctx, inData, outData)
+       }
+}
+
+// ScalarUnaryBoolOutput is like ScalarUnary only it is for cases of boolean
+// output. The function should take in a slice of the input type and a slice
+// of bytes to fill with the output boolean bitmap.
+func ScalarUnaryBoolOutput[Arg0T exec.FixedWidthTypes](op 
func(*exec.KernelCtx, []Arg0T, []byte) error) exec.ArrayKernelExec {
+       return func(ctx *exec.KernelCtx, in *exec.ExecSpan, out 
*exec.ExecResult) error {
+               arg0 := in.Values[0].Array
+               inData := exec.GetSpanValues[Arg0T](&arg0, 1)
+               return op(ctx, inData, out.Buffers[1].Buf)
+       }
+}
+
+// ScalarUnaryNotNullBinaryArgBoolOut creates a unary kernel that accepts
+// a binary type input (Binary [offset int32], String [offset int32],
+// LargeBinary [offset int64], LargeString [offset int64]) and returns
+// a boolean output which is never null.
+//
+// It implements the handling to iterate the offsets and values calling
+// the provided function on each byte slice. The provided default value
+// will be used as the output for elements of the input that are null.
+func ScalarUnaryNotNullBinaryArgBoolOut[OffsetT int32 | int64](defVal bool, op 
func(*exec.KernelCtx, []byte) (bool, error)) exec.ArrayKernelExec {

Review Comment:
   I've been following a pattern with naming these so far myself. But if you 
have any suggestions I'd be more than happy to consider them. :smile: 
   
   Essentially i've got 
`[Scalar|Vector][Arity](NotNull)((Binary|Bool)Arg)((Binary|Bool)Out)` for lack 
of a better representation lol.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to