github.com/matrixorigin/matrixone@v1.2.0/pkg/vm/engine/tae/compute/compute_test.go (about)

     1  // Copyright 2021 Matrix Origin
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //      http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package compute
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/stretchr/testify/require"
    21  
    22  	"github.com/RoaringBitmap/roaring"
    23  	"github.com/matrixorigin/matrixone/pkg/container/nulls"
    24  	"github.com/matrixorigin/matrixone/pkg/container/types"
    25  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/containers"
    26  	"github.com/matrixorigin/matrixone/pkg/vm/engine/tae/testutils"
    27  	"github.com/stretchr/testify/assert"
    28  )
    29  
    30  func TestShuffleByDeletes(t *testing.T) {
    31  	defer testutils.AfterTest(t)()
    32  	origMask := roaring.New()
    33  	origVals := make(map[uint32]any)
    34  	origMask.Add(1)
    35  	origVals[1] = 1
    36  	origMask.Add(10)
    37  	origVals[10] = 10
    38  	origMask.Add(20)
    39  	origVals[20] = 20
    40  	origMask.Add(30)
    41  	origVals[30] = 30
    42  
    43  	deletes := nulls.NewWithSize(1)
    44  	deletes.Add(0)
    45  	deletes.Add(8)
    46  	deletes.Add(22)
    47  
    48  	destDelets := ShuffleByDeletes(deletes, deletes)
    49  	t.Log(destDelets.String())
    50  }
    51  
    52  func TestCheckRowExists(t *testing.T) {
    53  	defer testutils.AfterTest(t)()
    54  	typ := types.T_int32.ToType()
    55  	vec := containers.MockVector2(typ, 100, 0)
    56  	_, exist := GetOffsetByVal(vec, int32(55), nil)
    57  	require.True(t, exist)
    58  	_, exist = GetOffsetByVal(vec, int32(0), nil)
    59  	require.True(t, exist)
    60  	_, exist = GetOffsetByVal(vec, int32(99), nil)
    61  	require.True(t, exist)
    62  
    63  	_, exist = GetOffsetByVal(vec, int32(-1), nil)
    64  	require.False(t, exist)
    65  	_, exist = GetOffsetByVal(vec, int32(100), nil)
    66  	require.False(t, exist)
    67  	_, exist = GetOffsetByVal(vec, int32(114514), nil)
    68  	require.False(t, exist)
    69  
    70  	dels := nulls.NewWithSize(1)
    71  	dels.Add(uint64(55))
    72  	_, exist = GetOffsetByVal(vec, int32(55), dels)
    73  	require.False(t, exist)
    74  }
    75  
    76  func TestAppendNull(t *testing.T) {
    77  	defer testutils.AfterTest(t)()
    78  	colTypes := types.MockColTypes()
    79  	check := func(typ types.Type) {
    80  		vec := containers.MockVector2(typ, 10, 0)
    81  		defer vec.Close()
    82  		vec.Append(nil, true)
    83  		assert.Equal(t, 11, vec.Length())
    84  		assert.True(t, vec.IsNull(10))
    85  		t.Log(vec.String())
    86  	}
    87  	for _, typ := range colTypes {
    88  		check(typ)
    89  	}
    90  }