github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/colexec/agg/aggUt/anyvalue_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/sql/colexec/agg"
    21  
    22  	"github.com/matrixorigin/matrixone/pkg/container/types"
    23  )
    24  
    25  const (
    26  	Rows = 10
    27  )
    28  
    29  func TestAnyvalue(t *testing.T) {
    30  	int8TestTyp := types.New(types.T_int8, 0, 0, 0)
    31  	decimalTestTyp := types.New(types.T_decimal128, 0, 0, 0)
    32  	boolTestTyp := types.New(types.T_bool, 0, 0, 0)
    33  	varcharTestTyp := types.New(types.T_varchar, types.MaxVarcharLen, 0, 0)
    34  	uuidTestTyp := types.New(types.T_uuid, 0, 0, 0)
    35  
    36  	testCases := []testCase{
    37  		// int8 anyvalue test
    38  		{
    39  			op:         agg.AggregateAnyValue,
    40  			isDistinct: false,
    41  			inputTyp:   int8TestTyp,
    42  
    43  			input:    []int8{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    44  			inputNsp: nil,
    45  			expected: []int8{9},
    46  
    47  			mergeInput:  []int8{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    48  			mergeNsp:    nil,
    49  			mergeExpect: []int8{9},
    50  
    51  			testMarshal: true,
    52  		},
    53  		// int8 distinct anyvalue test
    54  		{
    55  			op:         agg.AggregateAnyValue,
    56  			isDistinct: true,
    57  			inputTyp:   int8TestTyp,
    58  
    59  			input:    []int8{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    60  			inputNsp: nil,
    61  			expected: []int8{9},
    62  
    63  			mergeInput:  []int8{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    64  			mergeNsp:    nil,
    65  			mergeExpect: []int8{9},
    66  
    67  			testMarshal: false,
    68  		},
    69  		// decimal128 anyvalue test
    70  		{
    71  			op:         agg.AggregateAnyValue,
    72  			isDistinct: false,
    73  			inputTyp:   decimalTestTyp,
    74  
    75  			input:    []int64{9, 8, 7, 6, 5, 4, 3, 2, 1, 0},
    76  			inputNsp: nil,
    77  			expected: []int64{9},
    78  
    79  			mergeInput:  []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
    80  			mergeNsp:    nil,
    81  			mergeExpect: []int64{9},
    82  
    83  			testMarshal: true,
    84  		},
    85  		// bool anyvalue test
    86  		{
    87  			op:         agg.AggregateAnyValue,
    88  			isDistinct: false,
    89  			inputTyp:   boolTestTyp,
    90  
    91  			input:    []bool{true, true, false, true, false, true, false, true, false, true},
    92  			inputNsp: nil,
    93  			expected: []bool{true},
    94  
    95  			mergeInput:  []bool{false, false, false, false, false, false, false, false, false, false},
    96  			mergeNsp:    nil,
    97  			mergeExpect: []bool{true},
    98  
    99  			testMarshal: true,
   100  		},
   101  		// varchar anyvalue test
   102  		{
   103  			op:         agg.AggregateAnyValue,
   104  			isDistinct: false,
   105  			inputTyp:   varcharTestTyp,
   106  
   107  			input:    []string{"ab", "ac", "bc", "bcdd", "c", "za", "mo", "momo", "zb", "z"},
   108  			inputNsp: nil,
   109  			expected: []string{"ab"},
   110  
   111  			mergeInput:  []string{"ss", "ac", "bc", "bcdd", "c", "za", "mo", "momo", "zb", "z"},
   112  			mergeNsp:    nil,
   113  			mergeExpect: []string{"ab"},
   114  
   115  			testMarshal: true,
   116  		},
   117  		// uuid anyvalue test
   118  		{
   119  			op:         agg.AggregateAnyValue,
   120  			isDistinct: true,
   121  			inputTyp:   uuidTestTyp,
   122  
   123  			input: []string{
   124  				"1ef96142-2d0d-11ed-940f-000c29847904",
   125  				"f6355110-2d0c-11ed-940f-000c29847904",
   126  				"117a0bd5-2d0d-11ed-940f-000c29847904",
   127  				"18b21c70-2d0d-11ed-940f-000c29847904",
   128  				"1b50c129-2dba-11ed-940f-000c29847904",
   129  				"ad9f83eb-2dbd-11ed-940f-000c29847904",
   130  				"6d1b1fdb-2dbf-11ed-940f-000c29847904",
   131  				"6d1b1fdb-2dbf-11ed-940f-000c29847904",
   132  				"1b50c129-2dba-11ed-940f-000c29847904",
   133  				"ad9f83eb-2dbd-11ed-940f-000c29847904",
   134  			},
   135  			inputNsp: nil,
   136  			expected: []string{"1ef96142-2d0d-11ed-940f-000c29847904"},
   137  
   138  			mergeInput: []string{
   139  				"550e8400-e29b-41d4-a716-446655440000",
   140  				"3e350a5c-222a-11eb-abef-0242ac110002",
   141  				"9e7862b3-2f69-11ed-8ec0-000c29847904",
   142  				"6d1b1f73-2dbf-11ed-940f-000c29847904",
   143  				"ad9f809f-2dbd-11ed-940f-000c29847904",
   144  				"1b50c137-2dba-11ed-940f-000c29847904",
   145  				"149e3f0f-2de4-11ed-940f-000c29847904",
   146  				"1b50c137-2dba-11ed-940f-000c29847904",
   147  				"9e7862b3-2f69-11ed-8ec0-000c29847904",
   148  				"3F2504E0-4F89-11D3-9A0C-0305E82C3301",
   149  			},
   150  			mergeNsp:    nil,
   151  			mergeExpect: []string{"1ef96142-2d0d-11ed-940f-000c29847904"},
   152  
   153  			testMarshal: false,
   154  		},
   155  	}
   156  
   157  	RunTest(t, testCases)
   158  }