// 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.

//go:build go1.18

package kernels

import (
	
	

	
	
	
)

func isNonZero[ arrow.FixedWidthType]( *exec.KernelCtx,  [],  []byte) error {
	var  
	for ,  := range  {
		bitutil.SetBitTo(, ,  != )
	}
	return nil
}

// GetBooleanCastKernels returns the slice of scalar kernels for casting
// values *to* a boolean type.
func () []exec.ScalarKernel {
	 := GetCommonCastKernels(arrow.BOOL, exec.NewOutputType(arrow.FixedWidthTypes.Boolean))
	 = append(, GetZeroCastKernel(arrow.BOOL,
		exec.NewExactInput(arrow.FixedWidthTypes.Boolean), exec.NewOutputType(arrow.FixedWidthTypes.Boolean)))

	 := exec.NewOutputType(arrow.FixedWidthTypes.Boolean)
	for ,  := range numericTypes {
		var  exec.ArrayKernelExec
		switch .ID() {
		case arrow.INT8:
			 = ScalarUnaryBoolOutput(isNonZero[int8])
		case arrow.UINT8:
			 = ScalarUnaryBoolOutput(isNonZero[uint8])
		case arrow.INT16:
			 = ScalarUnaryBoolOutput(isNonZero[int16])
		case arrow.UINT16:
			 = ScalarUnaryBoolOutput(isNonZero[uint16])
		case arrow.INT32:
			 = ScalarUnaryBoolOutput(isNonZero[int32])
		case arrow.UINT32:
			 = ScalarUnaryBoolOutput(isNonZero[uint32])
		case arrow.INT64:
			 = ScalarUnaryBoolOutput(isNonZero[int64])
		case arrow.UINT64:
			 = ScalarUnaryBoolOutput(isNonZero[uint64])
		case arrow.FLOAT32:
			 = ScalarUnaryBoolOutput(isNonZero[float32])
		case arrow.FLOAT64:
			 = ScalarUnaryBoolOutput(isNonZero[float64])
		}
		 := exec.NewScalarKernel(
			[]exec.InputType{exec.NewExactInput()}, , , nil)
		.NullHandling = exec.NullIntersection
		.MemAlloc = exec.MemPrealloc
		 = append(, )
	}

	for ,  := range baseBinaryTypes {
		var  exec.ArrayKernelExec
		switch .ID() {
		case arrow.BINARY, arrow.STRING:
			 = ScalarUnaryNotNullBinaryArgBoolOut[int32](false, func( *exec.KernelCtx,  []byte,  *error) bool {
				 := *(*string)(unsafe.Pointer(&))
				,  := strconv.ParseBool()
				if  != nil {
					* = 
				}
				return 
			})
		case arrow.LARGE_BINARY, arrow.LARGE_STRING:
			 = ScalarUnaryNotNullBinaryArgBoolOut[int64](false, func( *exec.KernelCtx,  []byte,  *error) bool {
				 := *(*string)(unsafe.Pointer(&))
				,  := strconv.ParseBool()
				if  != nil {
					* = 
				}
				return 
			})
		}
		 := exec.NewScalarKernel(
			[]exec.InputType{exec.NewExactInput()}, , , nil)
		.NullHandling = exec.NullIntersection
		.MemAlloc = exec.MemPrealloc
		 = append(, )
	}

	return 
}