github.com/matrixorigin/matrixone@v0.7.0/pkg/partition/partition_test.go (about)

     1  // Copyright 2022 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 partition
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/common/mpool"
    21  	"github.com/matrixorigin/matrixone/pkg/container/types"
    22  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    23  	"github.com/stretchr/testify/require"
    24  
    25  	"github.com/matrixorigin/matrixone/pkg/container/nulls"
    26  )
    27  
    28  func TestPartition(t *testing.T) {
    29  	mp := mpool.MustNewZero()
    30  	v0 := vector.NewWithFixed(types.T_int8.ToType(), []int8{3, 4, 5, 6, 7, 8}, nil, mp)
    31  	partitions := make([]int64, 2)
    32  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v0)
    33  	require.Equal(t, []int64{0, 1}, partitions)
    34  	nulls.Add(v0.Nsp, 1)
    35  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v0)
    36  	require.Equal(t, []int64{0, 1}, partitions)
    37  
    38  	v1 := vector.NewWithFixed(types.T_int16.ToType(), []int16{3, 4, 5, 6, 7, 8}, nil, mp)
    39  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v1)
    40  	require.Equal(t, []int64{0, 1}, partitions)
    41  	nulls.Add(v0.Nsp, 1)
    42  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v1)
    43  	require.Equal(t, []int64{0, 1}, partitions)
    44  
    45  	v2 := vector.NewWithFixed(types.T_int32.ToType(), []int32{3, 4, 5, 6, 7, 8}, nil, mp)
    46  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v2)
    47  	require.Equal(t, []int64{0, 1}, partitions)
    48  	nulls.Add(v2.Nsp, 1)
    49  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v2)
    50  	require.Equal(t, []int64{0, 1}, partitions)
    51  
    52  	v3 := vector.NewWithFixed(types.T_int64.ToType(), []int64{3, 4, 5, 6, 7, 8}, nil, mp)
    53  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v3)
    54  	require.Equal(t, []int64{0, 1}, partitions)
    55  	nulls.Add(v3.Nsp, 1)
    56  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v3)
    57  	require.Equal(t, []int64{0, 1}, partitions)
    58  
    59  	v4 := vector.NewWithFixed(types.T_uint8.ToType(), []uint8{3, 4, 5, 6, 7, 8}, nil, mp)
    60  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v4)
    61  	require.Equal(t, []int64{0, 1}, partitions)
    62  	nulls.Add(v4.Nsp, 1)
    63  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v4)
    64  	require.Equal(t, []int64{0, 1}, partitions)
    65  
    66  	v5 := vector.NewWithFixed(types.T_uint16.ToType(), []uint16{3, 4, 5, 6, 7, 8}, nil, mp)
    67  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v5)
    68  	require.Equal(t, []int64{0, 1}, partitions)
    69  	nulls.Add(v5.Nsp, 1)
    70  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v5)
    71  	require.Equal(t, []int64{0, 1}, partitions)
    72  
    73  	v6 := vector.NewWithFixed(types.T_uint32.ToType(), []uint32{3, 4, 5, 6, 7, 8}, nil, mp)
    74  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v6)
    75  	require.Equal(t, []int64{0, 1}, partitions)
    76  	nulls.Add(v6.Nsp, 1)
    77  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v6)
    78  	require.Equal(t, []int64{0, 1}, partitions)
    79  
    80  	v7 := vector.NewWithFixed(types.T_uint64.ToType(), []uint64{3, 4, 5, 6, 7, 8}, nil, mp)
    81  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v7)
    82  	require.Equal(t, []int64{0, 1}, partitions)
    83  	nulls.Add(v7.Nsp, 1)
    84  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v7)
    85  	require.Equal(t, []int64{0, 1}, partitions)
    86  
    87  	v8 := vector.NewWithFixed(types.T_date.ToType(), []types.Date{3, 4, 5, 6, 7, 8}, nil, mp)
    88  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v8)
    89  	require.Equal(t, []int64{0, 1}, partitions)
    90  	nulls.Add(v8.Nsp, 1)
    91  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v8)
    92  	require.Equal(t, []int64{0, 1}, partitions)
    93  
    94  	v9 := vector.NewWithFixed(types.T_float32.ToType(), []float32{3, 4, 5, 6, 7, 8}, nil, mp)
    95  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v9)
    96  	require.Equal(t, []int64{0, 1}, partitions)
    97  	nulls.Add(v9.Nsp, 1)
    98  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v9)
    99  	require.Equal(t, []int64{0, 1}, partitions)
   100  
   101  	v10 := vector.NewWithFixed(types.T_float64.ToType(), []float64{3, 4, 5, 6, 7, 8}, nil, mp)
   102  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v10)
   103  	require.Equal(t, []int64{0, 1}, partitions)
   104  	nulls.Add(v10.Nsp, 1)
   105  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v10)
   106  	require.Equal(t, []int64{0, 1}, partitions)
   107  
   108  	v11 := vector.NewWithStrings(types.T_char.ToType(), []string{"hello", "Gut", "konichiwa", "nihao", "nihao", "nihao", "nihao"}, nil, mp)
   109  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v10)
   110  	require.Equal(t, []int64{0, 1}, partitions)
   111  	nulls.Add(v11.Nsp, 1)
   112  	Partition([]int64{1, 3, 5}, []bool{false, false, false}, partitions, v11)
   113  	require.Equal(t, []int64{0, 1}, partitions)
   114  }