github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/function/operator/isnotnull_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 operator
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  	"github.com/matrixorigin/matrixone/pkg/container/vector"
    22  	"github.com/matrixorigin/matrixone/pkg/testutil"
    23  )
    24  
    25  func TestIsNotNullNormal(t *testing.T) {
    26  	procs := testutil.NewProc()
    27  	vecs1 := []*vector.Vector{testutil.MakeInt32Vector([]int32{1, 14, 42, 7656, 4324234, 543534523}, nil)}
    28  	expected1 := []bool{true, true, true, true, true, true}
    29  	vecs2 := []*vector.Vector{testutil.MakeVarcharVector([]string{"1", "2", "3", "4"}, nil)}
    30  	expected2 := []bool{true, true, true, true}
    31  	vecs3 := []*vector.Vector{testutil.MakeTextVector([]string{"1", "2", "3", "4"}, nil)}
    32  	expected3 := []bool{true, true, true, true}
    33  
    34  	t.Run("isnotnull test - normal", func(t *testing.T) {
    35  		result, err := IsNotNull(vecs1, procs)
    36  		if err != nil {
    37  			t.Fatal(err)
    38  		}
    39  		checkIsNullResult(t, result, expected1, false)
    40  		result, err = IsNotNull(vecs2, procs)
    41  		if err != nil {
    42  			t.Fatal(err)
    43  		}
    44  		checkIsNullResult(t, result, expected2, false)
    45  		result, err = IsNotNull(vecs3, procs)
    46  		if err != nil {
    47  			t.Fatal(err)
    48  		}
    49  		checkIsNullResult(t, result, expected3, false)
    50  	})
    51  }
    52  
    53  func TestIsNotNullNormalWithNull(t *testing.T) {
    54  	procs := testutil.NewProc()
    55  	vecs1 := []*vector.Vector{testutil.MakeFloat64Vector([]float64{1, 14, 42, 7656, 4324234, 543534523}, []uint64{0, 1, 4})}
    56  	expected1 := []bool{false, false, true, true, false, true}
    57  	vecs2 := []*vector.Vector{testutil.MakeVarcharVector([]string{"1", "2", "3", "4"}, []uint64{0, 1, 3})}
    58  	expected2 := []bool{false, false, true, false}
    59  	vecs3 := []*vector.Vector{testutil.MakeTextVector([]string{"1", "2", "3", "4"}, []uint64{2, 3})}
    60  	expected3 := []bool{true, true, false, false}
    61  
    62  	t.Run("isnotnull test - normal with null", func(t *testing.T) {
    63  		result, err := IsNotNull(vecs1, procs)
    64  		if err != nil {
    65  			t.Fatal(err)
    66  		}
    67  		checkIsNullResult(t, result, expected1, false)
    68  		result, err = IsNotNull(vecs2, procs)
    69  		if err != nil {
    70  			t.Fatal(err)
    71  		}
    72  		checkIsNullResult(t, result, expected2, false)
    73  		result, err = IsNotNull(vecs3, procs)
    74  		if err != nil {
    75  			t.Fatal(err)
    76  		}
    77  		checkIsNullResult(t, result, expected3, false)
    78  	})
    79  }
    80  
    81  func TestIsNotNullScalar(t *testing.T) {
    82  	procs := testutil.NewProc()
    83  	vecs1 := []*vector.Vector{testutil.MakeScalarInt32(543534523, 1)}
    84  	expected1 := []bool{true}
    85  	vecs2 := []*vector.Vector{testutil.MakeScalarVarchar("hao", 1)}
    86  	expected2 := []bool{true}
    87  
    88  	t.Run("isnotnull test - not null scalar", func(t *testing.T) {
    89  		result, err := IsNotNull(vecs1, procs)
    90  		if err != nil {
    91  			t.Fatal(err)
    92  		}
    93  		checkIsNullResult(t, result, expected1, true)
    94  		result, err = IsNotNull(vecs2, procs)
    95  		if err != nil {
    96  			t.Fatal(err)
    97  		}
    98  		checkIsNullResult(t, result, expected2, true)
    99  	})
   100  }
   101  
   102  func TestIsNotNullScalarNull(t *testing.T) {
   103  	procs := testutil.NewProc()
   104  	vecs1 := []*vector.Vector{testutil.MakeScalarNull(types.T_bool, 1)}
   105  	expected1 := []bool{false}
   106  	vecs2 := []*vector.Vector{testutil.MakeScalarNull(types.T_bool, 1)}
   107  	expected2 := []bool{false}
   108  
   109  	t.Run("isnotnull test - scalar null", func(t *testing.T) {
   110  		result, err := IsNotNull(vecs1, procs)
   111  		if err != nil {
   112  			t.Fatal(err)
   113  		}
   114  		checkIsNullResult(t, result, expected1, true)
   115  		result, err = IsNotNull(vecs2, procs)
   116  		if err != nil {
   117  			t.Fatal(err)
   118  		}
   119  		checkIsNullResult(t, result, expected2, true)
   120  	})
   121  }