github.com/apache/arrow/go/v16@v16.1.0/arrow/compute/functions_test.go (about)

     1  // Licensed to the Apache Software Foundation (ASF) under one
     2  // or more contributor license agreements.  See the NOTICE file
     3  // distributed with this work for additional information
     4  // regarding copyright ownership.  The ASF licenses this file
     5  // to you under the Apache License, Version 2.0 (the
     6  // "License"); you may not use this file except in compliance
     7  // with the License.  You may obtain a copy of the License at
     8  //
     9  // http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing, software
    12  // distributed under the License is distributed on an "AS IS" BASIS,
    13  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14  // See the License for the specific language governing permissions and
    15  // limitations under the License.
    16  
    17  //go:build go1.18
    18  
    19  package compute_test
    20  
    21  import (
    22  	"testing"
    23  
    24  	"github.com/apache/arrow/go/v16/arrow"
    25  	"github.com/apache/arrow/go/v16/arrow/compute"
    26  	"github.com/stretchr/testify/assert"
    27  	"github.com/stretchr/testify/require"
    28  )
    29  
    30  func TestArityBasics(t *testing.T) {
    31  	nullary := compute.Nullary()
    32  	assert.Equal(t, 0, nullary.NArgs)
    33  	assert.False(t, nullary.IsVarArgs)
    34  
    35  	unary := compute.Unary()
    36  	assert.Equal(t, 1, unary.NArgs)
    37  	assert.False(t, unary.IsVarArgs)
    38  
    39  	binary := compute.Binary()
    40  	assert.Equal(t, 2, binary.NArgs)
    41  	assert.False(t, binary.IsVarArgs)
    42  
    43  	ternary := compute.Ternary()
    44  	assert.Equal(t, 3, ternary.NArgs)
    45  	assert.False(t, ternary.IsVarArgs)
    46  
    47  	varargs := compute.VarArgs(2)
    48  	assert.Equal(t, 2, varargs.NArgs)
    49  	assert.True(t, varargs.IsVarArgs)
    50  }
    51  
    52  func CheckDispatchBest(t *testing.T, funcName string, originalTypes, expected []arrow.DataType) {
    53  	fn, exists := compute.GetFunctionRegistry().GetFunction(funcName)
    54  	require.True(t, exists)
    55  
    56  	vals := make([]arrow.DataType, len(originalTypes))
    57  	copy(vals, originalTypes)
    58  
    59  	actualKernel, err := fn.DispatchBest(vals...)
    60  	require.NoError(t, err)
    61  	expKernel, err := fn.DispatchExact(expected...)
    62  	require.NoError(t, err)
    63  
    64  	assert.Same(t, expKernel, actualKernel)
    65  	assert.Equal(t, len(expected), len(vals))
    66  	for i, v := range vals {
    67  		assert.True(t, arrow.TypeEqual(v, expected[i]), v.String(), expected[i].String())
    68  	}
    69  }