github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/function/func_builtin_test.go (about) 1 // Copyright 2021 - 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 function 16 17 import ( 18 "fmt" 19 "github.com/matrixorigin/matrixone/pkg/common/mpool" 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/testutil" 23 "github.com/matrixorigin/matrixone/pkg/vm/process" 24 "github.com/stretchr/testify/require" 25 "math" 26 "testing" 27 ) 28 29 func Test_BuiltIn_CurrentSessionInfo(t *testing.T) { 30 proc := testutil.NewProcess() 31 proc.SessionInfo = process.SessionInfo{ 32 User: "test_user1", 33 UserId: 135, 34 Account: "test_account2", 35 AccountId: 246, 36 Role: "test_role3", 37 RoleId: 147, 38 } 39 40 { 41 tc := tcTemp{ 42 info: "select current_user_id()", 43 inputs: []testutil.FunctionTestInput{}, 44 expect: testutil.NewFunctionTestResult( 45 types.T_uint32.ToType(), false, 46 []uint32{135}, nil), 47 } 48 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentUserID) 49 succeed, info := tcc.Run() 50 require.True(t, succeed, tc.info, info) 51 } 52 53 { 54 tc := tcTemp{ 55 info: "select current_user_name()", 56 inputs: []testutil.FunctionTestInput{}, 57 expect: testutil.NewFunctionTestResult( 58 types.T_varchar.ToType(), false, 59 []string{"test_user1"}, nil), 60 } 61 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentUserName) 62 succeed, info := tcc.Run() 63 require.True(t, succeed, tc.info, info) 64 } 65 66 { 67 tc := tcTemp{ 68 info: "select current_account_id()", 69 inputs: []testutil.FunctionTestInput{}, 70 expect: testutil.NewFunctionTestResult( 71 types.T_uint32.ToType(), false, 72 []uint32{246}, nil), 73 } 74 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentAccountID) 75 succeed, info := tcc.Run() 76 require.True(t, succeed, tc.info, info) 77 } 78 79 { 80 tc := tcTemp{ 81 info: "select current_account_name()", 82 inputs: []testutil.FunctionTestInput{}, 83 expect: testutil.NewFunctionTestResult( 84 types.T_varchar.ToType(), false, 85 []string{"test_account2"}, nil), 86 } 87 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentAccountName) 88 succeed, info := tcc.Run() 89 require.True(t, succeed, tc.info, info) 90 } 91 92 { 93 tc := tcTemp{ 94 info: "select current_role_id()", 95 inputs: []testutil.FunctionTestInput{}, 96 expect: testutil.NewFunctionTestResult( 97 types.T_uint32.ToType(), false, 98 []uint32{147}, nil), 99 } 100 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentRoleID) 101 succeed, info := tcc.Run() 102 require.True(t, succeed, tc.info, info) 103 } 104 105 { 106 tc := tcTemp{ 107 info: "select current_role_name()", 108 inputs: []testutil.FunctionTestInput{}, 109 expect: testutil.NewFunctionTestResult( 110 types.T_varchar.ToType(), false, 111 []string{"test_role3"}, nil), 112 } 113 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentRoleName) 114 succeed, info := tcc.Run() 115 require.True(t, succeed, tc.info, info) 116 } 117 118 { 119 tc := tcTemp{ 120 info: "select current_role()", 121 inputs: []testutil.FunctionTestInput{}, 122 expect: testutil.NewFunctionTestResult( 123 types.T_varchar.ToType(), false, 124 []string{"test_role3"}, nil), 125 } 126 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCurrentRole) 127 succeed, info := tcc.Run() 128 require.True(t, succeed, tc.info, info) 129 } 130 } 131 132 func Test_BuiltIn_Rpad(t *testing.T) { 133 proc := testutil.NewProcess() 134 { 135 tc := tcTemp{ 136 info: "test rpad('hello', num, '#') with num = 0, 1, 10", 137 inputs: []testutil.FunctionTestInput{ 138 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 139 []string{"hello", "hello", "hello"}, nil), 140 testutil.NewFunctionTestInput(types.T_int64.ToType(), 141 []int64{0, 1, 10}, nil), 142 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 143 []string{"#", "#", "#"}, nil), 144 }, 145 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 146 []string{"", "h", "hello#####"}, nil), 147 } 148 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRpad) 149 succeed, info := tcc.Run() 150 require.True(t, succeed, tc.info, info) 151 } 152 153 { 154 tc := tcTemp{ 155 info: "test rpad('hello', num, '#@&') with num = 15", 156 inputs: []testutil.FunctionTestInput{ 157 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 158 []string{"hello"}, nil), 159 testutil.NewFunctionTestInput(types.T_int64.ToType(), 160 []int64{15}, nil), 161 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 162 []string{"#@&"}, nil), 163 }, 164 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 165 []string{"hello#@&#@&#@&#"}, nil), 166 } 167 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRpad) 168 succeed, info := tcc.Run() 169 require.True(t, succeed, tc.info, info) 170 } 171 172 { 173 tc := tcTemp{ 174 info: "test rpad('hello', num, '#@&') with num = 15, -1", 175 inputs: []testutil.FunctionTestInput{ 176 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 177 []string{"hello", "hello"}, []bool{false, false}), 178 testutil.NewFunctionTestInput(types.T_int64.ToType(), 179 []int64{15, -1}, nil), 180 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 181 []string{"#@&", "#@&"}, nil), 182 }, 183 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 184 []string{"hello#@&#@&#@&#", ""}, []bool{false, true}), 185 } 186 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRpad) 187 succeed, info := tcc.Run() 188 require.True(t, succeed, tc.info, info) 189 } 190 191 { 192 tc := tcTemp{ 193 info: "test rpad('你好', num, '再见') with num = 10", 194 inputs: []testutil.FunctionTestInput{ 195 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 196 []string{"你好"}, nil), 197 testutil.NewFunctionTestInput(types.T_int64.ToType(), 198 []int64{10}, nil), 199 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 200 []string{"再见"}, nil), 201 }, 202 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 203 []string{"你好再见再见再见再见"}, nil), 204 } 205 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRpad) 206 succeed, info := tcc.Run() 207 require.True(t, succeed, tc.info, info) 208 } 209 } 210 211 func Test_BuiltIn_Lpad(t *testing.T) { 212 proc := testutil.NewProcess() 213 { 214 tc := tcTemp{ 215 info: "test lpad('hello', num, '#') with num = 1, 10 \n" + 216 "test lpad('hello', num, '#@&') with num = 15", 217 inputs: []testutil.FunctionTestInput{ 218 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 219 []string{"hello", "hello", "hello"}, nil), 220 testutil.NewFunctionTestInput(types.T_int64.ToType(), 221 []int64{1, 10, 15}, nil), 222 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 223 []string{"#", "#", "#@&"}, nil), 224 }, 225 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 226 []string{"h", "#####hello", "#@&#@&#@&#hello"}, nil), 227 } 228 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLpad) 229 succeed, info := tcc.Run() 230 require.True(t, succeed, tc.info, info) 231 } 232 233 { 234 tc := tcTemp{ 235 info: "test lpad('12345678', num, 'abcdefgh') with num = 10", 236 inputs: []testutil.FunctionTestInput{ 237 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 238 []string{"12345678"}, nil), 239 testutil.NewFunctionTestInput(types.T_int64.ToType(), 240 []int64{10}, nil), 241 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 242 []string{"abcdefgh"}, nil), 243 }, 244 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 245 []string{"ab12345678"}, nil), 246 } 247 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLpad) 248 succeed, info := tcc.Run() 249 require.True(t, succeed, tc.info, info) 250 } 251 252 { 253 tc := tcTemp{ 254 info: "test lpad('你好', num, '再见') with num = 10", 255 inputs: []testutil.FunctionTestInput{ 256 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 257 []string{"你好"}, nil), 258 testutil.NewFunctionTestInput(types.T_int64.ToType(), 259 []int64{10}, nil), 260 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 261 []string{"再见"}, nil), 262 }, 263 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 264 []string{"再见再见再见再见你好"}, nil), 265 } 266 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLpad) 267 succeed, info := tcc.Run() 268 require.True(t, succeed, tc.info, info) 269 } 270 } 271 272 func Test_BuiltIn_Repeat(t *testing.T) { 273 proc := testutil.NewProcess() 274 { 275 tc := tcTemp{ 276 info: "test repeat('ab', num) with num = -1, 0, 1, 3, null, 1000000000000", 277 inputs: []testutil.FunctionTestInput{ 278 testutil.NewFunctionTestConstInput(types.T_varchar.ToType(), 279 []string{"ab"}, nil), 280 testutil.NewFunctionTestInput(types.T_int64.ToType(), 281 []int64{-1, 0, 1, 3, 0, 1000000000000}, []bool{false, false, false, false, true, false}), 282 }, 283 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 284 []string{"", "", "ab", "ababab", "", ""}, []bool{false, false, false, false, true, true}), 285 } 286 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRepeat) 287 succeed, info := tcc.Run() 288 require.True(t, succeed, tc.info, info) 289 } 290 291 { 292 tc := tcTemp{ 293 info: "test repeat(null, num) with num = -1, 0, 1, 3, null, 1000000000000", 294 inputs: []testutil.FunctionTestInput{ 295 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 296 []string{"", "", "", "", "", ""}, []bool{true, true, true, true, true, true}), 297 testutil.NewFunctionTestInput(types.T_int64.ToType(), 298 []int64{-1, 0, 1, 3, 0, 1000000000000}, []bool{false, false, false, false, true, false}), 299 }, 300 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 301 []string{"", "", "", "", "", ""}, []bool{true, true, true, true, true, true}), 302 } 303 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInRepeat) 304 succeed, info := tcc.Run() 305 require.True(t, succeed, tc.info, info) 306 } 307 } 308 309 func Test_BuiltIn_Serial(t *testing.T) { 310 proc := testutil.NewProcess() 311 312 input1 := []bool{true, false} 313 input2 := []int8{10, 1} 314 315 tc := tcTemp{ 316 info: "test serial(input1, input2)", 317 inputs: []testutil.FunctionTestInput{ 318 testutil.NewFunctionTestInput(types.T_bool.ToType(), 319 input1, nil), 320 testutil.NewFunctionTestInput(types.T_int8.ToType(), 321 input2, nil), 322 }, 323 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 324 []string{"serial(true, 10)", "serial(false, 1)"}, nil), 325 } 326 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, newOpSerial().BuiltInSerial) 327 tcc.Run() 328 329 vec := tcc.GetResultVectorDirectly() 330 p1 := vector.GenerateFunctionStrParameter(vec) 331 { 332 v, null := p1.GetStrValue(0) 333 require.False(t, null) 334 tuple, err := types.Unpack(v) 335 require.NoError(t, err) 336 require.Equal(t, input1[0], tuple[0]) 337 require.Equal(t, input2[0], tuple[1]) 338 } 339 { 340 v, null := p1.GetStrValue(1) 341 require.False(t, null) 342 tuple, err := types.Unpack(v) 343 require.NoError(t, err) 344 require.Equal(t, input1[1], tuple[0]) 345 require.Equal(t, input2[1], tuple[1]) 346 } 347 } 348 349 func Test_BuiltIn_SerialFull(t *testing.T) { 350 proc := testutil.NewProcess() 351 352 // serial_full functionality (preserving nulls) 353 input1 := []bool{true, false, true, true} 354 input1Nulls := []bool{true, false, true, true} 355 input2 := []int8{10, 1, 120, -1} 356 input2Nulls := []bool{false, true, false, true} 357 358 tc := tcTemp{ 359 info: "test serial_full(input1, input2)", 360 inputs: []testutil.FunctionTestInput{ 361 testutil.NewFunctionTestInput(types.T_bool.ToType(), input1, input1Nulls), 362 testutil.NewFunctionTestInput(types.T_int8.ToType(), input2, input2Nulls), 363 }, 364 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 365 []string{"serial_full(null, 10)", "serial_full(false, null)", "serial_full(null, 120)", "serial_full(null, null)"}, nil), 366 } 367 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, newOpSerial().BuiltInSerialFull) 368 tcc.Run() 369 370 vec := tcc.GetResultVectorDirectly() 371 p1 := vector.GenerateFunctionStrParameter(vec) 372 { 373 v, null := p1.GetStrValue(0) 374 require.False(t, null) 375 tuple, err := types.Unpack(v) 376 require.NoError(t, err) 377 require.Equal(t, nil, tuple[0]) // note: nulls are preserved 378 require.Equal(t, input2[0], tuple[1]) 379 } 380 { 381 v, null := p1.GetStrValue(1) 382 require.False(t, null) 383 tuple, err := types.Unpack(v) 384 require.NoError(t, err) 385 require.Equal(t, input1[1], tuple[0]) 386 require.Equal(t, nil, tuple[1]) // note: nulls are preserved 387 } 388 { 389 v, null := p1.GetStrValue(2) 390 require.False(t, null) 391 tuple, err := types.Unpack(v) 392 require.NoError(t, err) 393 require.Equal(t, nil, tuple[0]) // note: nulls are preserved 394 require.Equal(t, input2[2], tuple[1]) 395 } 396 { 397 v, null := p1.GetStrValue(3) 398 require.False(t, null) 399 tuple, err := types.Unpack(v) 400 require.NoError(t, err) 401 require.Equal(t, nil, tuple[0]) // note: nulls are preserved 402 require.Equal(t, nil, tuple[1]) // note: nulls are preserved 403 } 404 405 } 406 407 func initSerialExtractTestCase() []tcTemp { 408 mp := mpool.MustNewZero() 409 410 ps := types.NewPacker(mp) 411 ps.EncodeInt8(10) 412 ps.EncodeStringType([]byte("adam")) 413 414 return []tcTemp{ 415 { 416 info: "test serial_extract( serial(10,'adam'), 0 as Int8)", 417 inputs: []testutil.FunctionTestInput{ 418 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 419 []string{convertByteSliceToString(ps.Bytes())}, 420 []bool{false}), 421 testutil.NewFunctionTestInput(types.T_int64.ToType(), 422 []int64{0}, 423 []bool{false}), 424 testutil.NewFunctionTestInput(types.T_int8.ToType(), 425 []int8{0}, 426 []bool{false}), 427 }, 428 expect: testutil.NewFunctionTestResult(types.T_int8.ToType(), false, 429 []int8{10}, 430 []bool{false}), 431 }, 432 { 433 info: "test serial_extract( serial(10,'adam'), 1 as varchar)", 434 inputs: []testutil.FunctionTestInput{ 435 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 436 []string{convertByteSliceToString(ps.Bytes())}, 437 []bool{false}), 438 testutil.NewFunctionTestInput(types.T_int64.ToType(), 439 []int64{1}, 440 []bool{false}), 441 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 442 []string{""}, 443 []bool{false}), 444 }, 445 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), false, 446 []string{"adam"}, 447 []bool{false}), 448 }, 449 { 450 info: "test serial_extract( serial(10,'adam'), 2 as varchar)", 451 inputs: []testutil.FunctionTestInput{ 452 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 453 []string{convertByteSliceToString(ps.Bytes())}, 454 []bool{false}), 455 testutil.NewFunctionTestInput(types.T_int64.ToType(), 456 []int64{2}, 457 []bool{false}), 458 testutil.NewFunctionTestInput(types.T_varchar.ToType(), 459 []string{""}, 460 []bool{false}), 461 }, 462 expect: testutil.NewFunctionTestResult(types.T_varchar.ToType(), true, 463 []string{"adam"}, 464 []bool{false}), 465 }, 466 } 467 } 468 469 func TestSerialExtract(t *testing.T) { 470 testCases := initSerialExtractTestCase() 471 472 proc := testutil.NewProcess() 473 for _, tc := range testCases { 474 fcTC := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInSerialExtract) 475 s, info := fcTC.Run() 476 require.True(t, s, fmt.Sprintf("case is '%s', err info is '%s'", tc.info, info)) 477 } 478 } 479 480 func Test_BuiltIn_Math(t *testing.T) { 481 proc := testutil.NewProcess() 482 { 483 tc := tcTemp{ 484 info: "test ln", 485 inputs: []testutil.FunctionTestInput{ 486 testutil.NewFunctionTestInput(types.T_float64.ToType(), 487 []float64{ 488 1, math.Exp(0), math.Exp(1), math.Exp(10), math.Exp(100), math.Exp(99), math.Exp(-1), 489 }, 490 nil), 491 }, 492 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 493 []float64{0, 0, 1, 10, 100, 99, -1}, nil), 494 } 495 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLn) 496 succeed, info := tcc.Run() 497 require.True(t, succeed, tc.info, info) 498 } 499 500 { 501 tc := tcTemp{ 502 info: "test exp", 503 inputs: []testutil.FunctionTestInput{ 504 testutil.NewFunctionTestInput(types.T_float64.ToType(), 505 []float64{ 506 -1, 0, 1, 2, 10, 100, 507 }, 508 nil), 509 }, 510 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 511 []float64{math.Exp(-1), math.Exp(0), math.Exp(1), math.Exp(2), math.Exp(10), math.Exp(100)}, nil), 512 } 513 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInExp) 514 succeed, info := tcc.Run() 515 require.True(t, succeed, tc.info, info) 516 } 517 518 { 519 tc := tcTemp{ 520 info: "test sin", 521 inputs: []testutil.FunctionTestInput{ 522 testutil.NewFunctionTestInput(types.T_float64.ToType(), 523 []float64{ 524 -math.Pi / 2, 0, math.Pi / 2, 525 }, 526 nil), 527 }, 528 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 529 []float64{-1, 0, 1}, nil), 530 } 531 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInSin) 532 succeed, info := tcc.Run() 533 require.True(t, succeed, tc.info, info) 534 } 535 536 { 537 tc := tcTemp{ 538 info: "test cos", 539 inputs: []testutil.FunctionTestInput{ 540 testutil.NewFunctionTestInput(types.T_float64.ToType(), 541 []float64{ 542 -math.Pi, 0, math.Pi, 543 }, 544 nil), 545 }, 546 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 547 []float64{-1, 1, -1}, nil), 548 } 549 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInCos) 550 succeed, info := tcc.Run() 551 require.True(t, succeed, tc.info, info) 552 } 553 554 { 555 tc := tcTemp{ 556 info: "test tan", 557 inputs: []testutil.FunctionTestInput{ 558 testutil.NewFunctionTestInput(types.T_float64.ToType(), 559 []float64{ 560 0, 561 }, 562 nil), 563 }, 564 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 565 []float64{0}, nil), 566 } 567 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInTan) 568 succeed, info := tcc.Run() 569 require.True(t, succeed, tc.info, info) 570 } 571 572 { 573 tc := tcTemp{ 574 info: "test sinh", 575 inputs: []testutil.FunctionTestInput{ 576 testutil.NewFunctionTestInput(types.T_float64.ToType(), 577 []float64{ 578 0, 579 }, 580 nil), 581 }, 582 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 583 []float64{0}, nil), 584 } 585 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInSinh) 586 succeed, info := tcc.Run() 587 require.True(t, succeed, tc.info, info) 588 } 589 590 { 591 tc := tcTemp{ 592 info: "test acos", 593 inputs: []testutil.FunctionTestInput{ 594 testutil.NewFunctionTestInput(types.T_float64.ToType(), 595 []float64{ 596 1, 597 }, 598 nil), 599 }, 600 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 601 []float64{0}, nil), 602 } 603 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInACos) 604 succeed, info := tcc.Run() 605 require.True(t, succeed, tc.info, info) 606 } 607 608 { 609 tc := tcTemp{ 610 info: "test atan", 611 inputs: []testutil.FunctionTestInput{ 612 testutil.NewFunctionTestInput(types.T_float64.ToType(), 613 []float64{ 614 0, 615 }, 616 nil), 617 }, 618 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 619 []float64{0}, nil), 620 } 621 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInATan) 622 succeed, info := tcc.Run() 623 require.True(t, succeed, tc.info, info) 624 } 625 626 { 627 tc := tcTemp{ 628 info: "test atan with 2 args", 629 inputs: []testutil.FunctionTestInput{ 630 testutil.NewFunctionTestInput(types.T_float64.ToType(), 631 []float64{ 632 -1, 1, 1, 1, 1.0, 1.0, 633 }, 634 nil), 635 testutil.NewFunctionTestInput(types.T_float64.ToType(), 636 []float64{ 637 1, 0, -1, 1, -1.0, 1.0, 638 }, 639 nil), 640 }, 641 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 642 []float64{-0.7853981633974483, 0, -0.7853981633974483, 0.7853981633974483, -0.7853981633974483, 0.7853981633974483}, nil), 643 } 644 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInATan2) 645 succeed, info := tcc.Run() 646 require.True(t, succeed, tc.info, info) 647 } 648 649 { 650 tc := tcTemp{ 651 info: "test log", 652 inputs: []testutil.FunctionTestInput{ 653 testutil.NewFunctionTestInput(types.T_float64.ToType(), 654 []float64{ 655 5, 656 }, 657 nil), 658 testutil.NewFunctionTestInput(types.T_float64.ToType(), 659 []float64{ 660 3, 661 }, 662 nil), 663 }, 664 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 665 []float64{0.6826061944859853}, nil), 666 } 667 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog) 668 succeed, info := tcc.Run() 669 require.True(t, succeed, tc.info, info) 670 } 671 672 { 673 tc := tcTemp{ 674 info: "test log with err", 675 inputs: []testutil.FunctionTestInput{ 676 testutil.NewFunctionTestInput(types.T_float64.ToType(), 677 []float64{ 678 1, 679 }, 680 nil), 681 testutil.NewFunctionTestInput(types.T_float64.ToType(), 682 []float64{ 683 1, 684 }, 685 nil), 686 }, 687 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), true, 688 nil, nil), 689 } 690 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog) 691 succeed, info := tcc.Run() 692 require.True(t, succeed, tc.info, info) 693 } 694 695 { 696 tc := tcTemp{ 697 info: "test log2", 698 inputs: []testutil.FunctionTestInput{ 699 testutil.NewFunctionTestInput(types.T_float64.ToType(), 700 []float64{ 701 8, 702 }, 703 nil), 704 }, 705 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 706 []float64{3}, nil), 707 } 708 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog2) 709 succeed, info := tcc.Run() 710 require.True(t, succeed, tc.info, info) 711 } 712 713 { 714 tc := tcTemp{ 715 info: "test log2 with err", 716 inputs: []testutil.FunctionTestInput{ 717 testutil.NewFunctionTestInput(types.T_float64.ToType(), 718 []float64{ 719 -10, 720 }, 721 nil), 722 }, 723 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), true, 724 nil, nil), 725 } 726 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog2) 727 succeed, info := tcc.Run() 728 require.True(t, succeed, tc.info, info) 729 } 730 731 { 732 tc := tcTemp{ 733 info: "test log10", 734 inputs: []testutil.FunctionTestInput{ 735 testutil.NewFunctionTestInput(types.T_float64.ToType(), 736 []float64{ 737 100, 738 }, 739 nil), 740 }, 741 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), false, 742 []float64{2}, nil), 743 } 744 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog10) 745 succeed, info := tcc.Run() 746 require.True(t, succeed, tc.info, info) 747 } 748 749 { 750 tc := tcTemp{ 751 info: "test log10 with err", 752 inputs: []testutil.FunctionTestInput{ 753 testutil.NewFunctionTestInput(types.T_float64.ToType(), 754 []float64{ 755 -10, 756 }, 757 nil), 758 }, 759 expect: testutil.NewFunctionTestResult(types.T_float64.ToType(), true, 760 nil, nil), 761 } 762 tcc := testutil.NewFunctionTestCase(proc, tc.inputs, tc.expect, builtInLog10) 763 succeed, info := tcc.Run() 764 require.True(t, succeed, tc.info, info) 765 } 766 }