github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/aggUt/approxcd_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 aggut
    16  
    17  import (
    18  	"testing"
    19  
    20  	"github.com/matrixorigin/matrixone/pkg/container/types"
    21  	"github.com/matrixorigin/matrixone/pkg/sql/colexec/agg"
    22  )
    23  
    24  func TestApproxcdCount(t *testing.T) {
    25  	int8TestTyp := types.New(types.T_int8, 0, 0, 0)
    26  	decimal64Typ := types.New(types.T_decimal64, 0, 0, 0)
    27  	decimal128Typ := types.New(types.T_decimal128, 0, 0, 0)
    28  	testCases := []testCase{
    29  		{
    30  			op:         agg.AggregateApproxCountDistinct,
    31  			isDistinct: false,
    32  			inputTyp:   int8TestTyp,
    33  
    34  			input:    []int8{1, 1, 2, 2, 3, 3, 4, 4, 5, 5},
    35  			inputNsp: nil,
    36  			expected: []uint64{5},
    37  
    38  			mergeInput:  []int8{6, 6, 7, 7, 8, 8, 9, 9, 10, 10},
    39  			mergeNsp:    nil,
    40  			mergeExpect: []uint64{10},
    41  
    42  			testMarshal: true,
    43  		},
    44  		{
    45  			op:         agg.AggregateApproxCountDistinct,
    46  			isDistinct: false,
    47  			inputTyp:   decimal64Typ,
    48  
    49  			input:    []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    50  			inputNsp: nil,
    51  			expected: []uint64{10},
    52  
    53  			mergeInput:  []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    54  			mergeNsp:    nil,
    55  			mergeExpect: []uint64{10},
    56  
    57  			testMarshal: true,
    58  		},
    59  		{
    60  			op:         agg.AggregateApproxCountDistinct,
    61  			isDistinct: true,
    62  			inputTyp:   decimal64Typ,
    63  
    64  			input:    []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    65  			inputNsp: nil,
    66  			expected: []uint64{10},
    67  
    68  			mergeInput:  []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    69  			mergeNsp:    nil,
    70  			mergeExpect: []uint64{10},
    71  
    72  			testMarshal: false,
    73  		},
    74  		{
    75  			op:         agg.AggregateApproxCountDistinct,
    76  			isDistinct: false,
    77  			inputTyp:   decimal128Typ,
    78  
    79  			input:    []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    80  			inputNsp: nil,
    81  			expected: []uint64{10},
    82  
    83  			mergeInput:  []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    84  			mergeNsp:    nil,
    85  			mergeExpect: []uint64{10},
    86  
    87  			testMarshal: true,
    88  		},
    89  		{
    90  			op:         agg.AggregateApproxCountDistinct,
    91  			isDistinct: true,
    92  			inputTyp:   decimal128Typ,
    93  
    94  			input:    []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    95  			inputNsp: nil,
    96  			expected: []uint64{10},
    97  
    98  			mergeInput:  []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    99  			mergeNsp:    nil,
   100  			mergeExpect: []uint64{10},
   101  
   102  			testMarshal: false,
   103  		},
   104  	}
   105  
   106  	RunTest(t, testCases)
   107  }