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