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