github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/function/baseTemplate.go (about) 1 // Copyright 2021 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 "github.com/matrixorigin/matrixone/pkg/common/moerr" 19 "github.com/matrixorigin/matrixone/pkg/container/nulls" 20 "github.com/matrixorigin/matrixone/pkg/container/types" 21 "github.com/matrixorigin/matrixone/pkg/container/vector" 22 "github.com/matrixorigin/matrixone/pkg/sql/plan/function/functionUtil" 23 "github.com/matrixorigin/matrixone/pkg/vm/process" 24 "golang.org/x/exp/constraints" 25 ) 26 27 type templateTp1 interface { 28 bool 29 } 30 31 type templateTr1 interface { 32 bool 33 } 34 35 // For sca. 36 var _ = opBinaryFixedStrToFixedWithErrorCheck[bool, bool] 37 var _ = opNoneParamToBytesWithErrorCheck 38 var _ = opBinaryStrFixedToStrWithErrorCheck[bool] 39 40 // I hope it can generate all functions according to some easy parameters. 41 // not yet ok. and may change soon. plz use it carefully if you really need it. 42 func generalFunctionTemplateFactor[T1 templateTp1, T2 templateTr1]( 43 fValueNull func(v1 T1) (T2, bool), alwaysNull1 bool, 44 fNullValue func(v2 T1) (T2, bool), alwaysNull2 bool, 45 fValueValue func(v1, v2 T1) (T2, bool), neverNull bool, 46 fNullNull func() (T1, bool), alwaysNull3 bool, canFold bool) func(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int) error { 47 if !canFold { 48 panic("cannot support template for function cannot fold now") 49 } 50 51 // very basic template. 52 // if any one of params was null, result is null. 53 // and never occurs null if all params were not null. 54 if alwaysNull1 && alwaysNull2 && alwaysNull3 && neverNull { 55 return func(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int) error { 56 p1 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[0]) 57 p2 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[1]) 58 rs := vector.MustFunctionResult[T2](result) 59 rsVec := rs.GetResultVector() 60 rss := vector.MustFixedCol[T2](rsVec) 61 62 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 63 if c1 && c2 { 64 v1, null1 := p1.GetValue(0) 65 v2, null2 := p2.GetValue(0) 66 ifNull := null1 || null2 67 if ifNull { 68 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 69 } else { 70 r, _ := fValueValue(v1, v2) 71 rowCount := uint64(length) 72 for i := uint64(0); i < rowCount; i++ { 73 rss[i] = r 74 } 75 } 76 return nil 77 } 78 79 if c1 { 80 v1, null1 := p1.GetValue(0) 81 if null1 { 82 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 83 } else { 84 if p2.WithAnyNullValue() { 85 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 86 rowCount := uint64(length) 87 for i := uint64(0); i < rowCount; i++ { 88 v2, null2 := p2.GetValue(i) 89 if null2 { 90 continue 91 } 92 r, _ := fValueValue(v1, v2) 93 rss[i] = r 94 } 95 } else { 96 rowCount := uint64(length) 97 for i := uint64(0); i < rowCount; i++ { 98 v2, _ := p2.GetValue(i) 99 rss[i], _ = fValueValue(v1, v2) 100 } 101 } 102 } 103 return nil 104 } 105 106 if c2 { 107 v2, null2 := p2.GetValue(0) 108 if null2 { 109 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 110 } else { 111 if p1.WithAnyNullValue() { 112 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 113 rowCount := uint64(length) 114 for i := uint64(0); i < rowCount; i++ { 115 v1, null1 := p1.GetValue(i) 116 if null1 { 117 continue 118 } 119 r, _ := fValueValue(v1, v2) 120 rss[i] = r 121 } 122 } else { 123 rowCount := uint64(length) 124 for i := uint64(0); i < rowCount; i++ { 125 v1, _ := p1.GetValue(i) 126 rss[i], _ = fValueValue(v1, v2) 127 } 128 } 129 } 130 return nil 131 } 132 133 // basic case. 134 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 135 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 136 } 137 138 rowCount := uint64(length) 139 for i := uint64(0); i < rowCount; i++ { 140 v1, _ := p1.GetValue(i) 141 v2, _ := p2.GetValue(i) 142 rss[i], _ = fValueValue(v1, v2) 143 } 144 return nil 145 } 146 } 147 148 // return null if all params were null. but not certain if only one param was null. 149 // result will be not null if all params were not null. 150 if alwaysNull3 && neverNull && (!alwaysNull1 && !alwaysNull2) { 151 return func(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int) error { 152 p1 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[0]) 153 p2 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[1]) 154 rs := vector.MustFunctionResult[T2](result) 155 rsVec := rs.GetResultVector() 156 rss := vector.MustFixedCol[T2](rsVec) 157 158 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 159 160 if c1 && c2 { 161 v1, null1 := p1.GetValue(0) 162 v2, null2 := p2.GetValue(0) 163 if null1 && null2 { 164 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 165 } else if null1 { 166 v, rnull := fNullValue(v2) 167 if rnull { 168 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 169 } else { 170 rowCount := uint64(length) 171 for i := uint64(0); i < rowCount; i++ { 172 rss[i] = v 173 } 174 } 175 } else if null2 { 176 v, rnull := fValueNull(v1) 177 if rnull { 178 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 179 } else { 180 rowCount := uint64(length) 181 for i := uint64(0); i < rowCount; i++ { 182 rss[i] = v 183 } 184 } 185 } else { 186 v, _ := fValueValue(v1, v2) 187 rowCount := uint64(length) 188 for i := uint64(0); i < rowCount; i++ { 189 rss[i] = v 190 } 191 } 192 193 return nil 194 } 195 196 if c1 { 197 v1, null1 := p1.GetValue(0) 198 if !null1 { 199 if p2.WithAnyNullValue() { 200 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 201 rowCount := uint64(length) 202 for i := uint64(0); i < rowCount; i++ { 203 v2, null2 := p2.GetValue(i) 204 if null2 { 205 r, ifnull := fValueNull(v1) 206 if !ifnull { 207 rsVec.GetNulls().Del(i) 208 rss[i] = r 209 } 210 } else { 211 rss[i], _ = fValueValue(v1, v2) 212 } 213 } 214 } else { 215 rowCount := uint64(length) 216 for i := uint64(0); i < rowCount; i++ { 217 v2, _ := p2.GetValue(i) 218 rss[i], _ = fValueValue(v1, v2) 219 } 220 } 221 } else { 222 if p2.WithAnyNullValue() { 223 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 224 rowCount := uint64(length) 225 for i := uint64(0); i < rowCount; i++ { 226 v2, null2 := p2.GetValue(i) 227 if null2 { 228 continue 229 } else { 230 r, ifnull := fNullValue(v2) 231 if ifnull { 232 rsVec.GetNulls().Add(i) 233 } else { 234 rss[i] = r 235 } 236 } 237 } 238 } else { 239 if rsVec.GetNulls() == nil { 240 rsVec.SetNulls(nulls.NewWithSize(0)) 241 } 242 rowCount := uint64(length) 243 for i := uint64(0); i < rowCount; i++ { 244 v2, _ := p2.GetValue(i) 245 r, ifnull := fNullValue(v2) 246 if ifnull { 247 rsVec.GetNulls().Add(i) 248 } else { 249 rss[i] = r 250 } 251 } 252 } 253 } 254 return nil 255 } 256 257 if c2 { 258 v2, null2 := p2.GetValue(0) 259 if !null2 { 260 if p1.WithAnyNullValue() { 261 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 262 rowCount := uint64(length) 263 for i := uint64(0); i < rowCount; i++ { 264 v1, null1 := p1.GetValue(i) 265 if null1 { 266 r, ifnull := fNullValue(v2) 267 if !ifnull { 268 rsVec.GetNulls().Del(i) 269 rss[i] = r 270 } 271 } else { 272 rss[i], _ = fValueValue(v1, v2) 273 } 274 } 275 } else { 276 rowCount := uint64(length) 277 for i := uint64(0); i < rowCount; i++ { 278 v1, _ := p1.GetValue(i) 279 rss[i], _ = fValueValue(v1, v2) 280 } 281 } 282 return nil 283 284 } else { 285 if p1.WithAnyNullValue() { 286 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 287 rowCount := uint64(length) 288 for i := uint64(0); i < rowCount; i++ { 289 v1, null1 := p1.GetValue(i) 290 if null1 { 291 continue 292 } else { 293 r, ifnull := fValueNull(v1) 294 if ifnull { 295 rsVec.GetNulls().Add(i) 296 } else { 297 rss[i] = r 298 } 299 } 300 } 301 } else { 302 if rsVec.GetNulls() == nil { 303 rsVec.SetNulls(nulls.NewWithSize(0)) 304 } 305 rowCount := uint64(length) 306 for i := uint64(0); i < rowCount; i++ { 307 v1, _ := p1.GetValue(i) 308 r, ifnull := fValueNull(v1) 309 if ifnull { 310 rsVec.GetNulls().Add(i) 311 } else { 312 rss[i] = r 313 } 314 } 315 } 316 } 317 return nil 318 } 319 320 // normal vector op normal vector 321 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 322 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 323 324 rowCount := uint64(length) 325 for i := uint64(0); i < rowCount; i++ { 326 v1, null1 := p1.GetValue(i) 327 v2, null2 := p2.GetValue(i) 328 if null1 && !null2 { 329 r, rnull := fNullValue(v2) 330 if !rnull { 331 rsVec.GetNulls().Del(i) 332 rss[i] = r 333 } 334 } else if null2 && !null1 { 335 r, rnull := fValueNull(v1) 336 if !rnull { 337 rsVec.GetNulls().Del(i) 338 rss[i] = r 339 } 340 } else if !null1 && !null2 { 341 rss[i], _ = fValueValue(v1, v2) 342 } 343 } 344 return nil 345 } 346 347 rowCount := uint64(length) 348 for i := uint64(0); i < rowCount; i++ { 349 v1, _ := p1.GetValue(i) 350 v2, _ := p2.GetValue(i) 351 rss[i], _ = fValueValue(v1, v2) 352 } 353 return nil 354 } 355 } 356 357 panic("unsupported function template.") 358 } 359 360 type templateDec interface { 361 types.Decimal64 | types.Decimal128 362 } 363 364 func decimal128ArithArray(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 365 arithFn func(v1, v2, rs []types.Decimal128, scale1, scale2 int32, null1, null2 *nulls.Nulls) error) error { 366 p1 := vector.GenerateFunctionFixedTypeParameter[types.Decimal128](parameters[0]) 367 p2 := vector.GenerateFunctionFixedTypeParameter[types.Decimal128](parameters[1]) 368 rs := vector.MustFunctionResult[types.Decimal128](result) 369 rsVec := rs.GetResultVector() 370 rss := vector.MustFixedCol[types.Decimal128](rsVec) 371 scale1 := p1.GetType().Scale 372 scale2 := p2.GetType().Scale 373 374 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 375 if c1 { 376 _, null1 := p1.GetValue(0) 377 if null1 { 378 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 379 return nil 380 } 381 } 382 if c2 { 383 _, null2 := p2.GetValue(0) 384 if null2 { 385 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 386 return nil 387 } 388 } 389 390 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 391 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 392 } 393 v1 := vector.MustFixedCol[types.Decimal128](p1.GetSourceVector()) 394 v2 := vector.MustFixedCol[types.Decimal128](p2.GetSourceVector()) 395 err := arithFn(v1, v2, rss, scale1, scale2, parameters[0].GetNulls(), parameters[1].GetNulls()) 396 if err != nil { 397 return err 398 } 399 return nil 400 } 401 402 func decimalArith[T templateDec](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 403 arithFn func(v1, v2 T, scale1, scale2 int32) (T, error)) error { 404 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 405 p2 := vector.GenerateFunctionFixedTypeParameter[T](parameters[1]) 406 rs := vector.MustFunctionResult[T](result) 407 rsVec := rs.GetResultVector() 408 rss := vector.MustFixedCol[T](rsVec) 409 410 scale1 := p1.GetType().Scale 411 scale2 := p2.GetType().Scale 412 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 413 if c1 && c2 { 414 v1, null1 := p1.GetValue(0) 415 v2, null2 := p2.GetValue(0) 416 ifNull := null1 || null2 417 if ifNull { 418 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 419 } else { 420 r, err := arithFn(v1, v2, scale1, scale2) 421 if err != nil { 422 return err 423 } 424 rowCount := uint64(length) 425 for i := uint64(0); i < rowCount; i++ { 426 rss[i] = r 427 } 428 } 429 return nil 430 } 431 432 if c1 { 433 v1, null1 := p1.GetValue(0) 434 if null1 { 435 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 436 } else { 437 if p2.WithAnyNullValue() { 438 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 439 rowCount := uint64(length) 440 for i := uint64(0); i < rowCount; i++ { 441 v2, null2 := p2.GetValue(i) 442 if null2 { 443 continue 444 } 445 r, err := arithFn(v1, v2, scale1, scale2) 446 if err != nil { 447 return err 448 } 449 rss[i] = r 450 } 451 } else { 452 rowCount := uint64(length) 453 for i := uint64(0); i < rowCount; i++ { 454 v2, _ := p2.GetValue(i) 455 r, err := arithFn(v1, v2, scale1, scale2) 456 if err != nil { 457 return err 458 } 459 rss[i] = r 460 } 461 } 462 } 463 return nil 464 } 465 466 if c2 { 467 v2, null2 := p2.GetValue(0) 468 if null2 { 469 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 470 } else { 471 if p1.WithAnyNullValue() { 472 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 473 rowCount := uint64(length) 474 for i := uint64(0); i < rowCount; i++ { 475 v1, null1 := p1.GetValue(i) 476 if null1 { 477 continue 478 } 479 r, err := arithFn(v1, v2, scale1, scale2) 480 if err != nil { 481 return err 482 } 483 rss[i] = r 484 } 485 } else { 486 rowCount := uint64(length) 487 for i := uint64(0); i < rowCount; i++ { 488 v1, _ := p1.GetValue(i) 489 r, err := arithFn(v1, v2, scale1, scale2) 490 if err != nil { 491 return err 492 } 493 rss[i] = r 494 } 495 } 496 } 497 return nil 498 } 499 500 // basic case. 501 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 502 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 503 504 rowCount := uint64(length) 505 for i := uint64(0); i < rowCount; i++ { 506 v1, null1 := p1.GetValue(i) 507 v2, null2 := p2.GetValue(i) 508 if null1 || null2 { 509 continue 510 } 511 r, err := arithFn(v1, v2, scale1, scale2) 512 if err != nil { 513 return err 514 } 515 rss[i] = r 516 } 517 return nil 518 } 519 520 rowCount := uint64(length) 521 for i := uint64(0); i < rowCount; i++ { 522 v1, _ := p1.GetValue(i) 523 v2, _ := p2.GetValue(i) 524 r, err := arithFn(v1, v2, scale1, scale2) 525 if err != nil { 526 return err 527 } 528 rss[i] = r 529 } 530 return nil 531 } 532 533 // XXX For decimal64 / decimal64, decimal64 * decimal64 534 func decimalArith2(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 535 arithFn func(v1, v2 types.Decimal128, scale1, scale2 int32) (types.Decimal128, error)) error { 536 p1 := vector.GenerateFunctionFixedTypeParameter[types.Decimal64](parameters[0]) 537 p2 := vector.GenerateFunctionFixedTypeParameter[types.Decimal64](parameters[1]) 538 rs := vector.MustFunctionResult[types.Decimal128](result) 539 rsVec := rs.GetResultVector() 540 rss := vector.MustFixedCol[types.Decimal128](rsVec) 541 542 scale1 := p1.GetType().Scale 543 scale2 := p2.GetType().Scale 544 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 545 if c1 && c2 { 546 v1, null1 := p1.GetValue(0) 547 v2, null2 := p2.GetValue(0) 548 if null1 || null2 { 549 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 550 } else { 551 x, y := functionUtil.ConvertD64ToD128(v1), functionUtil.ConvertD64ToD128(v2) 552 r, err := arithFn(x, y, scale1, scale2) 553 if err != nil { 554 return err 555 } 556 rowCount := uint64(length) 557 for i := uint64(0); i < rowCount; i++ { 558 rss[i] = r 559 } 560 } 561 return nil 562 } 563 564 if c1 { 565 v1, null1 := p1.GetValue(0) 566 if null1 { 567 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 568 } else { 569 if p2.WithAnyNullValue() { 570 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 571 572 x := functionUtil.ConvertD64ToD128(v1) 573 rowCount := uint64(length) 574 for i := uint64(0); i < rowCount; i++ { 575 v2, null2 := p2.GetValue(i) 576 if null2 { 577 continue 578 } 579 y := functionUtil.ConvertD64ToD128(v2) 580 r, err := arithFn(x, y, scale1, scale2) 581 if err != nil { 582 return err 583 } 584 rss[i] = r 585 } 586 } else { 587 x := functionUtil.ConvertD64ToD128(v1) 588 rowCount := uint64(length) 589 for i := uint64(0); i < rowCount; i++ { 590 v2, _ := p2.GetValue(i) 591 y := functionUtil.ConvertD64ToD128(v2) 592 r, err := arithFn(x, y, scale1, scale2) 593 if err != nil { 594 return err 595 } 596 rss[i] = r 597 } 598 } 599 } 600 return nil 601 } 602 603 if c2 { 604 v2, null2 := p2.GetValue(0) 605 if null2 { 606 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 607 } else { 608 if p1.WithAnyNullValue() { 609 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 610 611 y := functionUtil.ConvertD64ToD128(v2) 612 rowCount := uint64(length) 613 for i := uint64(0); i < rowCount; i++ { 614 v1, null1 := p1.GetValue(i) 615 if null1 { 616 continue 617 } 618 x := functionUtil.ConvertD64ToD128(v1) 619 r, err := arithFn(x, y, scale1, scale2) 620 if err != nil { 621 return err 622 } 623 rss[i] = r 624 } 625 } else { 626 y := functionUtil.ConvertD64ToD128(v2) 627 rowCount := uint64(length) 628 for i := uint64(0); i < rowCount; i++ { 629 v1, _ := p1.GetValue(i) 630 x := functionUtil.ConvertD64ToD128(v1) 631 r, err := arithFn(x, y, scale1, scale2) 632 if err != nil { 633 return err 634 } 635 rss[i] = r 636 } 637 } 638 } 639 return nil 640 } 641 642 // basic case. 643 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 644 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 645 646 rowCount := uint64(length) 647 for i := uint64(0); i < rowCount; i++ { 648 v1, null1 := p1.GetValue(i) 649 v2, null2 := p2.GetValue(i) 650 if null1 || null2 { 651 continue 652 } 653 x, y := functionUtil.ConvertD64ToD128(v1), functionUtil.ConvertD64ToD128(v2) 654 r, err := arithFn(x, y, scale1, scale2) 655 if err != nil { 656 return err 657 } 658 rss[i] = r 659 } 660 return nil 661 } 662 663 rowCount := uint64(length) 664 for i := uint64(0); i < rowCount; i++ { 665 v1, _ := p1.GetValue(i) 666 v2, _ := p2.GetValue(i) 667 x, y := functionUtil.ConvertD64ToD128(v1), functionUtil.ConvertD64ToD128(v2) 668 r, err := arithFn(x, y, scale1, scale2) 669 if err != nil { 670 return err 671 } 672 rss[i] = r 673 } 674 return nil 675 } 676 677 // opBinaryFixedFixedToFixed for binary functions whose 678 // result of f(x, y) is null if any one of x, y is null value. 679 // and if x, y were all normal value, result will not be an error. 680 func opBinaryFixedFixedToFixed[ 681 T1 types.FixedSizeTExceptStrType, 682 T2 types.FixedSizeTExceptStrType, 683 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 684 resultFn func(v1 T1, v2 T2) Tr) error { 685 p1 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[0]) 686 p2 := vector.GenerateFunctionFixedTypeParameter[T2](parameters[1]) 687 rs := vector.MustFunctionResult[Tr](result) 688 rsVec := rs.GetResultVector() 689 rss := vector.MustFixedCol[Tr](rsVec) 690 691 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 692 if c1 && c2 { 693 v1, null1 := p1.GetValue(0) 694 v2, null2 := p2.GetValue(0) 695 ifNull := null1 || null2 696 if ifNull { 697 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 698 } else { 699 r := resultFn(v1, v2) 700 rowCount := uint64(length) 701 for i := uint64(0); i < rowCount; i++ { 702 rss[i] = r 703 } 704 } 705 return nil 706 } 707 708 if c1 { 709 v1, null1 := p1.GetValue(0) 710 if null1 { 711 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 712 } else { 713 if p2.WithAnyNullValue() { 714 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 715 rowCount := uint64(length) 716 for i := uint64(0); i < rowCount; i++ { 717 v2, null2 := p2.GetValue(i) 718 if null2 { 719 continue 720 } 721 rss[i] = resultFn(v1, v2) 722 } 723 } else { 724 rowCount := uint64(length) 725 for i := uint64(0); i < rowCount; i++ { 726 v2, _ := p2.GetValue(i) 727 rss[i] = resultFn(v1, v2) 728 } 729 } 730 } 731 return nil 732 } 733 734 if c2 { 735 v2, null2 := p2.GetValue(0) 736 if null2 { 737 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 738 } else { 739 if p1.WithAnyNullValue() { 740 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 741 rowCount := uint64(length) 742 for i := uint64(0); i < rowCount; i++ { 743 v1, null1 := p1.GetValue(i) 744 if null1 { 745 continue 746 } 747 rss[i] = resultFn(v1, v2) 748 } 749 } else { 750 rowCount := uint64(length) 751 for i := uint64(0); i < rowCount; i++ { 752 v1, _ := p1.GetValue(i) 753 rss[i] = resultFn(v1, v2) 754 } 755 } 756 } 757 return nil 758 } 759 760 // basic case. 761 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 762 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 763 rowCount := uint64(length) 764 for i := uint64(0); i < rowCount; i++ { 765 v1, null1 := p1.GetValue(i) 766 v2, null2 := p2.GetValue(i) 767 if null1 || null2 { 768 continue 769 } 770 rss[i] = resultFn(v1, v2) 771 } 772 return nil 773 } 774 775 rowCount := uint64(length) 776 for i := uint64(0); i < rowCount; i++ { 777 v1, _ := p1.GetValue(i) 778 v2, _ := p2.GetValue(i) 779 rss[i] = resultFn(v1, v2) 780 } 781 return nil 782 } 783 784 func opBinaryFixedFixedToFixedWithErrorCheck[ 785 T1 types.FixedSizeTExceptStrType, 786 T2 types.FixedSizeTExceptStrType, 787 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 788 resultFn func(v1 T1, v2 T2) (Tr, error)) error { 789 p1 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[0]) 790 p2 := vector.GenerateFunctionFixedTypeParameter[T2](parameters[1]) 791 rs := vector.MustFunctionResult[Tr](result) 792 rsVec := rs.GetResultVector() 793 rss := vector.MustFixedCol[Tr](rsVec) 794 795 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 796 if c1 && c2 { 797 v1, null1 := p1.GetValue(0) 798 v2, null2 := p2.GetValue(0) 799 ifNull := null1 || null2 800 if ifNull { 801 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 802 } else { 803 r, err := resultFn(v1, v2) 804 if err != nil { 805 return err 806 } 807 rowCount := uint64(length) 808 for i := uint64(0); i < rowCount; i++ { 809 rss[i] = r 810 } 811 } 812 return nil 813 } 814 815 if c1 { 816 v1, null1 := p1.GetValue(0) 817 if null1 { 818 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 819 } else { 820 if p2.WithAnyNullValue() { 821 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 822 rowCount := uint64(length) 823 for i := uint64(0); i < rowCount; i++ { 824 v2, null2 := p2.GetValue(i) 825 if null2 { 826 continue 827 } 828 r, err := resultFn(v1, v2) 829 if err != nil { 830 return err 831 } 832 rss[i] = r 833 } 834 } else { 835 rowCount := uint64(length) 836 for i := uint64(0); i < rowCount; i++ { 837 v2, _ := p2.GetValue(i) 838 r, err := resultFn(v1, v2) 839 if err != nil { 840 return err 841 } 842 rss[i] = r 843 } 844 } 845 } 846 return nil 847 } 848 849 if c2 { 850 v2, null2 := p2.GetValue(0) 851 if null2 { 852 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 853 } else { 854 if p1.WithAnyNullValue() { 855 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 856 rowCount := uint64(length) 857 for i := uint64(0); i < rowCount; i++ { 858 v1, null1 := p1.GetValue(i) 859 if null1 { 860 continue 861 } 862 r, err := resultFn(v1, v2) 863 if err != nil { 864 return err 865 } 866 rss[i] = r 867 } 868 } else { 869 rowCount := uint64(length) 870 for i := uint64(0); i < rowCount; i++ { 871 v1, _ := p1.GetValue(i) 872 r, err := resultFn(v1, v2) 873 if err != nil { 874 return err 875 } 876 rss[i] = r 877 } 878 } 879 } 880 return nil 881 } 882 883 // basic case. 884 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 885 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 886 rowCount := uint64(length) 887 for i := uint64(0); i < rowCount; i++ { 888 v1, null1 := p1.GetValue(i) 889 v2, null2 := p2.GetValue(i) 890 if null1 || null2 { 891 continue 892 } 893 r, err := resultFn(v1, v2) 894 if err != nil { 895 return err 896 } 897 rss[i] = r 898 } 899 return nil 900 } 901 902 rowCount := uint64(length) 903 for i := uint64(0); i < rowCount; i++ { 904 v1, _ := p1.GetValue(i) 905 v2, _ := p2.GetValue(i) 906 r, err := resultFn(v1, v2) 907 if err != nil { 908 return err 909 } 910 rss[i] = r 911 } 912 return nil 913 } 914 915 func opBinaryStrFixedToFixedWithErrorCheck[ 916 T2 types.FixedSizeTExceptStrType, 917 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 918 resultFn func(v1 string, v2 T2) (Tr, error)) error { 919 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 920 p2 := vector.GenerateFunctionFixedTypeParameter[T2](parameters[1]) 921 rs := vector.MustFunctionResult[Tr](result) 922 rsVec := rs.GetResultVector() 923 rss := vector.MustFixedCol[Tr](rsVec) 924 925 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 926 if c1 && c2 { 927 v1, null1 := p1.GetStrValue(0) 928 v2, null2 := p2.GetValue(0) 929 ifNull := null1 || null2 930 if ifNull { 931 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 932 } else { 933 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 934 if err != nil { 935 return err 936 } 937 rowCount := uint64(length) 938 for i := uint64(0); i < rowCount; i++ { 939 rss[i] = r 940 } 941 } 942 return nil 943 } 944 945 if c1 { 946 v1, null1 := p1.GetStrValue(0) 947 if null1 { 948 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 949 } else { 950 if p2.WithAnyNullValue() { 951 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 952 rowCount := uint64(length) 953 rv1 := functionUtil.QuickBytesToStr(v1) 954 for i := uint64(0); i < rowCount; i++ { 955 v2, null2 := p2.GetValue(i) 956 if null2 { 957 continue 958 } 959 r, err := resultFn(rv1, v2) 960 if err != nil { 961 return err 962 } 963 rss[i] = r 964 } 965 } else { 966 rv1 := functionUtil.QuickBytesToStr(v1) 967 rowCount := uint64(length) 968 for i := uint64(0); i < rowCount; i++ { 969 v2, _ := p2.GetValue(i) 970 r, err := resultFn(rv1, v2) 971 if err != nil { 972 return err 973 } 974 rss[i] = r 975 } 976 } 977 } 978 return nil 979 } 980 981 if c2 { 982 v2, null2 := p2.GetValue(0) 983 if null2 { 984 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 985 } else { 986 if p1.WithAnyNullValue() { 987 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 988 rowCount := uint64(length) 989 for i := uint64(0); i < rowCount; i++ { 990 v1, null1 := p1.GetStrValue(i) 991 if null1 { 992 continue 993 } 994 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 995 if err != nil { 996 return err 997 } 998 rss[i] = r 999 } 1000 } else { 1001 rowCount := uint64(length) 1002 for i := uint64(0); i < rowCount; i++ { 1003 v1, _ := p1.GetStrValue(i) 1004 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1005 if err != nil { 1006 return err 1007 } 1008 rss[i] = r 1009 } 1010 } 1011 } 1012 return nil 1013 } 1014 1015 // basic case. 1016 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1017 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1018 rowCount := uint64(length) 1019 for i := uint64(0); i < rowCount; i++ { 1020 v1, null1 := p1.GetStrValue(i) 1021 v2, null2 := p2.GetValue(i) 1022 if null1 || null2 { 1023 continue 1024 } 1025 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1026 if err != nil { 1027 return err 1028 } 1029 rss[i] = r 1030 } 1031 return nil 1032 } 1033 1034 rowCount := uint64(length) 1035 for i := uint64(0); i < rowCount; i++ { 1036 v1, _ := p1.GetStrValue(i) 1037 v2, _ := p2.GetValue(i) 1038 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1039 if err != nil { 1040 return err 1041 } 1042 rss[i] = r 1043 } 1044 return nil 1045 } 1046 1047 func opBinaryStrFixedToStrWithErrorCheck[ 1048 T2 types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1049 resultFn func(v1 string, v2 T2) (string, error)) error { 1050 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 1051 p2 := vector.GenerateFunctionFixedTypeParameter[T2](parameters[1]) 1052 rs := vector.MustFunctionResult[types.Varlena](result) 1053 rsVec := rs.GetResultVector() 1054 1055 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1056 if c1 && c2 { 1057 v1, null1 := p1.GetStrValue(0) 1058 v2, null2 := p2.GetValue(0) 1059 ifNull := null1 || null2 1060 if ifNull { 1061 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1062 } else { 1063 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1064 if err != nil { 1065 return err 1066 } 1067 rowCount := uint64(length) 1068 for i := uint64(0); i < rowCount; i++ { 1069 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1070 return err 1071 } 1072 } 1073 } 1074 return nil 1075 } 1076 1077 if c1 { 1078 v1, null1 := p1.GetStrValue(0) 1079 if null1 { 1080 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1081 } else { 1082 if p2.WithAnyNullValue() { 1083 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1084 rowCount := uint64(length) 1085 rv1 := functionUtil.QuickBytesToStr(v1) 1086 for i := uint64(0); i < rowCount; i++ { 1087 v2, null2 := p2.GetValue(i) 1088 if null2 { 1089 continue 1090 } 1091 r, err := resultFn(rv1, v2) 1092 if err != nil { 1093 return err 1094 } 1095 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1096 return err 1097 } 1098 } 1099 } else { 1100 rv1 := functionUtil.QuickBytesToStr(v1) 1101 rowCount := uint64(length) 1102 for i := uint64(0); i < rowCount; i++ { 1103 v2, _ := p2.GetValue(i) 1104 r, err := resultFn(rv1, v2) 1105 if err != nil { 1106 return err 1107 } 1108 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1109 return err 1110 } 1111 } 1112 } 1113 } 1114 return nil 1115 } 1116 1117 if c2 { 1118 v2, null2 := p2.GetValue(0) 1119 if null2 { 1120 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1121 } else { 1122 if p1.WithAnyNullValue() { 1123 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1124 rowCount := uint64(length) 1125 for i := uint64(0); i < rowCount; i++ { 1126 v1, null1 := p1.GetStrValue(i) 1127 if null1 { 1128 continue 1129 } 1130 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1131 if err != nil { 1132 return err 1133 } 1134 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1135 return err 1136 } 1137 } 1138 } else { 1139 rowCount := uint64(length) 1140 for i := uint64(0); i < rowCount; i++ { 1141 v1, _ := p1.GetStrValue(i) 1142 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1143 if err != nil { 1144 return err 1145 } 1146 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1147 return err 1148 } 1149 } 1150 } 1151 } 1152 return nil 1153 } 1154 1155 // basic case. 1156 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1157 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1158 rowCount := uint64(length) 1159 for i := uint64(0); i < rowCount; i++ { 1160 v1, null1 := p1.GetStrValue(i) 1161 v2, null2 := p2.GetValue(i) 1162 if null1 || null2 { 1163 continue 1164 } 1165 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1166 if err != nil { 1167 return err 1168 } 1169 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1170 return err 1171 } 1172 } 1173 return nil 1174 } 1175 1176 rowCount := uint64(length) 1177 for i := uint64(0); i < rowCount; i++ { 1178 v1, _ := p1.GetStrValue(i) 1179 v2, _ := p2.GetValue(i) 1180 r, err := resultFn(functionUtil.QuickBytesToStr(v1), v2) 1181 if err != nil { 1182 return err 1183 } 1184 if err = rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 1185 return err 1186 } 1187 } 1188 return nil 1189 } 1190 1191 func opBinaryFixedStrToFixedWithErrorCheck[ 1192 T1 types.FixedSizeTExceptStrType, 1193 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1194 resultFn func(v1 T1, v2 string) (Tr, error)) error { 1195 p1 := vector.GenerateFunctionFixedTypeParameter[T1](parameters[0]) 1196 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 1197 rs := vector.MustFunctionResult[Tr](result) 1198 rsVec := rs.GetResultVector() 1199 rss := vector.MustFixedCol[Tr](rsVec) 1200 1201 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1202 if c1 && c2 { 1203 v1, null1 := p1.GetValue(0) 1204 v2, null2 := p2.GetStrValue(0) 1205 ifNull := null1 || null2 1206 if ifNull { 1207 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1208 } else { 1209 r, err := resultFn(v1, functionUtil.QuickBytesToStr(v2)) 1210 if err != nil { 1211 return err 1212 } 1213 rowCount := uint64(length) 1214 for i := uint64(0); i < rowCount; i++ { 1215 rss[i] = r 1216 } 1217 } 1218 return nil 1219 } 1220 1221 if c1 { 1222 v1, null1 := p1.GetValue(0) 1223 if null1 { 1224 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1225 } else { 1226 if p2.WithAnyNullValue() { 1227 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1228 rowCount := uint64(length) 1229 for i := uint64(0); i < rowCount; i++ { 1230 v2, null2 := p2.GetStrValue(i) 1231 if null2 { 1232 continue 1233 } 1234 r, err := resultFn(v1, functionUtil.QuickBytesToStr(v2)) 1235 if err != nil { 1236 return err 1237 } 1238 rss[i] = r 1239 } 1240 } else { 1241 rowCount := uint64(length) 1242 for i := uint64(0); i < rowCount; i++ { 1243 v2, _ := p2.GetStrValue(i) 1244 r, err := resultFn(v1, functionUtil.QuickBytesToStr(v2)) 1245 if err != nil { 1246 return err 1247 } 1248 rss[i] = r 1249 } 1250 } 1251 } 1252 return nil 1253 } 1254 1255 if c2 { 1256 v2, null2 := p2.GetStrValue(0) 1257 if null2 { 1258 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1259 } else { 1260 rv2 := functionUtil.QuickBytesToStr(v2) 1261 if p1.WithAnyNullValue() { 1262 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1263 rowCount := uint64(length) 1264 for i := uint64(0); i < rowCount; i++ { 1265 v1, null1 := p1.GetValue(i) 1266 if null1 { 1267 continue 1268 } 1269 r, err := resultFn(v1, rv2) 1270 if err != nil { 1271 return err 1272 } 1273 rss[i] = r 1274 } 1275 } else { 1276 rowCount := uint64(length) 1277 for i := uint64(0); i < rowCount; i++ { 1278 v1, _ := p1.GetValue(i) 1279 r, err := resultFn(v1, rv2) 1280 if err != nil { 1281 return err 1282 } 1283 rss[i] = r 1284 } 1285 } 1286 } 1287 return nil 1288 } 1289 1290 // basic case. 1291 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1292 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1293 rowCount := uint64(length) 1294 for i := uint64(0); i < rowCount; i++ { 1295 v1, null1 := p1.GetValue(i) 1296 v2, null2 := p2.GetStrValue(i) 1297 if null1 || null2 { 1298 continue 1299 } 1300 r, err := resultFn(v1, functionUtil.QuickBytesToStr(v2)) 1301 if err != nil { 1302 return err 1303 } 1304 rss[i] = r 1305 } 1306 return nil 1307 } 1308 1309 rowCount := uint64(length) 1310 for i := uint64(0); i < rowCount; i++ { 1311 v1, _ := p1.GetValue(i) 1312 v2, _ := p2.GetStrValue(i) 1313 r, err := resultFn(v1, functionUtil.QuickBytesToStr(v2)) 1314 if err != nil { 1315 return err 1316 } 1317 rss[i] = r 1318 } 1319 return nil 1320 } 1321 1322 func specialTemplateForModFunction[ 1323 T constraints.Integer | constraints.Float](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1324 modFn func(v1, v2 T) T) error { 1325 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 1326 p2 := vector.GenerateFunctionFixedTypeParameter[T](parameters[1]) 1327 rs := vector.MustFunctionResult[T](result) 1328 rsVec := rs.GetResultVector() 1329 rss := vector.MustFixedCol[T](rsVec) 1330 1331 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1332 if c1 && c2 { 1333 v1, null1 := p1.GetValue(0) 1334 v2, null2 := p2.GetValue(0) 1335 ifNull := null1 || null2 1336 if ifNull || v2 == 0 { 1337 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1338 } else { 1339 r := modFn(v1, v2) 1340 rowCount := uint64(length) 1341 for i := uint64(0); i < rowCount; i++ { 1342 rss[i] = r 1343 } 1344 } 1345 return nil 1346 } 1347 1348 if c1 { 1349 v1, null1 := p1.GetValue(0) 1350 if null1 { 1351 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1352 } else { 1353 if p2.WithAnyNullValue() { 1354 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1355 rowCount := uint64(length) 1356 for i := uint64(0); i < rowCount; i++ { 1357 v2, null2 := p2.GetValue(i) 1358 if null2 { 1359 continue 1360 } 1361 if v2 == 0 { 1362 rsVec.GetNulls().Add(i) 1363 } else { 1364 rss[i] = modFn(v1, v2) 1365 } 1366 } 1367 } else { 1368 if rsVec.GetNulls() == nil { 1369 rsVec.SetNulls(nulls.NewWithSize(0)) 1370 } 1371 rowCount := uint64(length) 1372 for i := uint64(0); i < rowCount; i++ { 1373 v2, _ := p2.GetValue(i) 1374 if v2 == 0 { 1375 rsVec.GetNulls().Add(i) 1376 } else { 1377 rss[i] = modFn(v1, v2) 1378 } 1379 } 1380 } 1381 } 1382 return nil 1383 } 1384 1385 if c2 { 1386 v2, null2 := p2.GetValue(0) 1387 if null2 || v2 == 0 { 1388 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1389 } else { 1390 if p1.WithAnyNullValue() { 1391 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1392 rowCount := uint64(length) 1393 for i := uint64(0); i < rowCount; i++ { 1394 v1, null1 := p1.GetValue(i) 1395 if null1 { 1396 continue 1397 } 1398 rss[i] = modFn(v1, v2) 1399 } 1400 } else { 1401 rowCount := uint64(length) 1402 for i := uint64(0); i < rowCount; i++ { 1403 v1, _ := p1.GetValue(i) 1404 rss[i] = modFn(v1, v2) 1405 } 1406 } 1407 } 1408 return nil 1409 } 1410 1411 // basic case. 1412 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1413 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1414 rowCount := uint64(length) 1415 for i := uint64(0); i < rowCount; i++ { 1416 v1, null1 := p1.GetValue(i) 1417 v2, null2 := p2.GetValue(i) 1418 if null1 || null2 { 1419 continue 1420 } 1421 if v2 == 0 { 1422 rsVec.GetNulls().Add(i) 1423 } else { 1424 rss[i] = modFn(v1, v2) 1425 } 1426 } 1427 return nil 1428 } 1429 1430 if rsVec.GetNulls() == nil { 1431 rsVec.SetNulls(nulls.NewWithSize(0)) 1432 } 1433 rowCount := uint64(length) 1434 for i := uint64(0); i < rowCount; i++ { 1435 v1, _ := p1.GetValue(i) 1436 v2, _ := p2.GetValue(i) 1437 if v2 == 0 { 1438 rsVec.GetNulls().Add(i) 1439 } else { 1440 rss[i] = modFn(v1, v2) 1441 } 1442 } 1443 return nil 1444 } 1445 1446 func specialTemplateForDivFunction[ 1447 T constraints.Float, T2 constraints.Float | int64](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1448 divFn func(v1, v2 T) T2) error { 1449 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 1450 p2 := vector.GenerateFunctionFixedTypeParameter[T](parameters[1]) 1451 rs := vector.MustFunctionResult[T2](result) 1452 rsVec := rs.GetResultVector() 1453 rss := vector.MustFixedCol[T2](rsVec) 1454 1455 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1456 if c1 && c2 { 1457 v1, null1 := p1.GetValue(0) 1458 v2, null2 := p2.GetValue(0) 1459 ifNull := null1 || null2 1460 if ifNull { 1461 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1462 } else { 1463 if v2 == 0 { 1464 return moerr.NewDivByZeroNoCtx() 1465 } 1466 r := divFn(v1, v2) 1467 rowCount := uint64(length) 1468 for i := uint64(0); i < rowCount; i++ { 1469 rss[i] = r 1470 } 1471 } 1472 return nil 1473 } 1474 1475 if c1 { 1476 v1, null1 := p1.GetValue(0) 1477 if null1 { 1478 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1479 } else { 1480 if p2.WithAnyNullValue() { 1481 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1482 rowCount := uint64(length) 1483 for i := uint64(0); i < rowCount; i++ { 1484 v2, null2 := p2.GetValue(i) 1485 if null2 { 1486 continue 1487 } 1488 if v2 == 0 { 1489 return moerr.NewDivByZeroNoCtx() 1490 } else { 1491 rss[i] = divFn(v1, v2) 1492 } 1493 } 1494 } else { 1495 rowCount := uint64(length) 1496 for i := uint64(0); i < rowCount; i++ { 1497 v2, _ := p2.GetValue(i) 1498 if v2 == 0 { 1499 return moerr.NewDivByZeroNoCtx() 1500 } else { 1501 rss[i] = divFn(v1, v2) 1502 } 1503 } 1504 } 1505 } 1506 return nil 1507 } 1508 1509 if c2 { 1510 v2, null2 := p2.GetValue(0) 1511 if null2 { 1512 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1513 } else { 1514 if v2 == 0 { 1515 return moerr.NewDivByZeroNoCtx() 1516 } 1517 if p1.WithAnyNullValue() { 1518 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1519 rowCount := uint64(length) 1520 for i := uint64(0); i < rowCount; i++ { 1521 v1, null1 := p1.GetValue(i) 1522 if null1 { 1523 continue 1524 } 1525 rss[i] = divFn(v1, v2) 1526 } 1527 } else { 1528 rowCount := uint64(length) 1529 for i := uint64(0); i < rowCount; i++ { 1530 v1, _ := p1.GetValue(i) 1531 rss[i] = divFn(v1, v2) 1532 } 1533 } 1534 } 1535 return nil 1536 } 1537 1538 // basic case. 1539 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1540 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1541 rowCount := uint64(length) 1542 for i := uint64(0); i < rowCount; i++ { 1543 v1, null1 := p1.GetValue(i) 1544 v2, null2 := p2.GetValue(i) 1545 if null1 || null2 { 1546 continue 1547 } 1548 if v2 == 0 { 1549 return moerr.NewDivByZeroNoCtx() 1550 } else { 1551 rss[i] = divFn(v1, v2) 1552 } 1553 } 1554 return nil 1555 } 1556 1557 rowCount := uint64(length) 1558 for i := uint64(0); i < rowCount; i++ { 1559 v1, _ := p1.GetValue(i) 1560 v2, _ := p2.GetValue(i) 1561 if v2 == 0 { 1562 return moerr.NewDivByZeroNoCtx() 1563 } else { 1564 rss[i] = divFn(v1, v2) 1565 } 1566 } 1567 return nil 1568 } 1569 1570 func opBinaryBytesBytesToFixed[Tr types.FixedSizeTExceptStrType]( 1571 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1572 arithFn func(v1, v2 []byte) Tr) error { 1573 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 1574 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 1575 rs := vector.MustFunctionResult[Tr](result) 1576 rsVec := rs.GetResultVector() 1577 rss := vector.MustFixedCol[Tr](rsVec) 1578 1579 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1580 if c1 && c2 { 1581 v1, null1 := p1.GetStrValue(0) 1582 v2, null2 := p2.GetStrValue(0) 1583 ifNull := null1 || null2 1584 if ifNull { 1585 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1586 } else { 1587 r := arithFn(v1, v2) 1588 rowCount := uint64(length) 1589 for i := uint64(0); i < rowCount; i++ { 1590 rss[i] = r 1591 } 1592 } 1593 return nil 1594 } 1595 1596 if c1 { 1597 v1, null1 := p1.GetStrValue(0) 1598 if null1 { 1599 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1600 } else { 1601 if p2.WithAnyNullValue() { 1602 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1603 rowCount := uint64(length) 1604 for i := uint64(0); i < rowCount; i++ { 1605 v2, null2 := p2.GetStrValue(i) 1606 if null2 { 1607 continue 1608 } 1609 rss[i] = arithFn(v1, v2) 1610 } 1611 } else { 1612 rowCount := uint64(length) 1613 for i := uint64(0); i < rowCount; i++ { 1614 v2, _ := p2.GetStrValue(i) 1615 rss[i] = arithFn(v1, v2) 1616 } 1617 } 1618 } 1619 return nil 1620 } 1621 1622 if c2 { 1623 v2, null2 := p2.GetStrValue(0) 1624 if null2 { 1625 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1626 } else { 1627 if p1.WithAnyNullValue() { 1628 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1629 rowCount := uint64(length) 1630 for i := uint64(0); i < rowCount; i++ { 1631 v1, null1 := p1.GetStrValue(i) 1632 if null1 { 1633 continue 1634 } 1635 rss[i] = arithFn(v1, v2) 1636 } 1637 } else { 1638 rowCount := uint64(length) 1639 for i := uint64(0); i < rowCount; i++ { 1640 v1, _ := p1.GetStrValue(i) 1641 rss[i] = arithFn(v1, v2) 1642 } 1643 } 1644 } 1645 return nil 1646 } 1647 1648 // basic case. 1649 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1650 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1651 rowCount := uint64(length) 1652 for i := uint64(0); i < rowCount; i++ { 1653 v1, null1 := p1.GetStrValue(i) 1654 v2, null2 := p2.GetStrValue(i) 1655 if null1 || null2 { 1656 continue 1657 } 1658 rss[i] = arithFn(v1, v2) 1659 } 1660 return nil 1661 } 1662 1663 rowCount := uint64(length) 1664 for i := uint64(0); i < rowCount; i++ { 1665 v1, _ := p1.GetStrValue(i) 1666 v2, _ := p2.GetStrValue(i) 1667 rss[i] = arithFn(v1, v2) 1668 } 1669 return nil 1670 } 1671 1672 func opBinaryBytesBytesToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType]( 1673 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1674 fn func(v1, v2 []byte) (Tr, error)) error { 1675 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 1676 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 1677 rs := vector.MustFunctionResult[Tr](result) 1678 rsVec := rs.GetResultVector() 1679 rss := vector.MustFixedCol[Tr](rsVec) 1680 1681 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1682 if c1 && c2 { 1683 v1, null1 := p1.GetStrValue(0) 1684 v2, null2 := p2.GetStrValue(0) 1685 ifNull := null1 || null2 1686 if ifNull { 1687 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1688 } else { 1689 r, err := fn(v1, v2) 1690 if err != nil { 1691 return err 1692 } 1693 rowCount := uint64(length) 1694 for i := uint64(0); i < rowCount; i++ { 1695 rss[i] = r 1696 } 1697 } 1698 return nil 1699 } 1700 1701 var err error 1702 if c1 { 1703 v1, null1 := p1.GetStrValue(0) 1704 if null1 { 1705 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1706 } else { 1707 if p2.WithAnyNullValue() { 1708 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1709 rowCount := uint64(length) 1710 for i := uint64(0); i < rowCount; i++ { 1711 v2, null2 := p2.GetStrValue(i) 1712 if null2 { 1713 continue 1714 } 1715 rss[i], err = fn(v1, v2) 1716 if err != nil { 1717 return err 1718 } 1719 } 1720 } else { 1721 rowCount := uint64(length) 1722 for i := uint64(0); i < rowCount; i++ { 1723 v2, _ := p2.GetStrValue(i) 1724 rss[i], err = fn(v1, v2) 1725 if err != nil { 1726 return err 1727 } 1728 } 1729 } 1730 } 1731 return nil 1732 } 1733 1734 if c2 { 1735 v2, null2 := p2.GetStrValue(0) 1736 if null2 { 1737 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1738 } else { 1739 if p1.WithAnyNullValue() { 1740 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1741 rowCount := uint64(length) 1742 for i := uint64(0); i < rowCount; i++ { 1743 v1, null1 := p1.GetStrValue(i) 1744 if null1 { 1745 continue 1746 } 1747 rss[i], err = fn(v1, v2) 1748 if err != nil { 1749 return err 1750 } 1751 } 1752 } else { 1753 rowCount := uint64(length) 1754 for i := uint64(0); i < rowCount; i++ { 1755 v1, _ := p1.GetStrValue(i) 1756 rss[i], err = fn(v1, v2) 1757 if err != nil { 1758 return err 1759 } 1760 } 1761 } 1762 } 1763 return nil 1764 } 1765 1766 // basic case. 1767 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1768 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1769 rowCount := uint64(length) 1770 for i := uint64(0); i < rowCount; i++ { 1771 v1, null1 := p1.GetStrValue(i) 1772 v2, null2 := p2.GetStrValue(i) 1773 if null1 || null2 { 1774 continue 1775 } 1776 rss[i], err = fn(v1, v2) 1777 if err != nil { 1778 return err 1779 } 1780 } 1781 return nil 1782 } 1783 1784 rowCount := uint64(length) 1785 for i := uint64(0); i < rowCount; i++ { 1786 v1, _ := p1.GetStrValue(i) 1787 v2, _ := p2.GetStrValue(i) 1788 rss[i], err = fn(v1, v2) 1789 if err != nil { 1790 return err 1791 } 1792 } 1793 return nil 1794 } 1795 1796 func opBinaryBytesBytesToBytesWithErrorCheck( 1797 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1798 fn func(v1, v2 []byte) ([]byte, error)) error { 1799 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 1800 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 1801 rs := vector.MustFunctionResult[types.Varlena](result) 1802 rsVec := rs.GetResultVector() 1803 1804 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 1805 if c1 && c2 { 1806 v1, null1 := p1.GetStrValue(0) 1807 v2, null2 := p2.GetStrValue(0) 1808 ifNull := null1 || null2 1809 if ifNull { 1810 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1811 } else { 1812 r, err := fn(v1, v2) 1813 if err != nil { 1814 return err 1815 } 1816 rowCount := uint64(length) 1817 for i := uint64(0); i < rowCount; i++ { 1818 if err = rs.AppendMustBytesValue(r); err != nil { 1819 return err 1820 } 1821 } 1822 } 1823 return nil 1824 } 1825 1826 if c1 { 1827 v1, null1 := p1.GetStrValue(0) 1828 if null1 { 1829 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1830 } else { 1831 if p2.WithAnyNullValue() { 1832 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1833 rowCount := uint64(length) 1834 for i := uint64(0); i < rowCount; i++ { 1835 v2, null2 := p2.GetStrValue(i) 1836 if null2 { 1837 err := rs.AppendMustNullForBytesResult() 1838 if err != nil { 1839 return err 1840 } 1841 continue 1842 } 1843 r, err := fn(v1, v2) 1844 if err != nil { 1845 return err 1846 } 1847 1848 if err = rs.AppendMustBytesValue(r); err != nil { 1849 return err 1850 } 1851 } 1852 } else { 1853 rowCount := uint64(length) 1854 for i := uint64(0); i < rowCount; i++ { 1855 v2, _ := p2.GetStrValue(i) 1856 r, err := fn(v1, v2) 1857 if err != nil { 1858 return err 1859 } 1860 1861 if err = rs.AppendMustBytesValue(r); err != nil { 1862 return err 1863 } 1864 } 1865 } 1866 } 1867 return nil 1868 } 1869 1870 if c2 { 1871 v2, null2 := p2.GetStrValue(0) 1872 if null2 { 1873 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1874 } else { 1875 if p1.WithAnyNullValue() { 1876 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 1877 rowCount := uint64(length) 1878 for i := uint64(0); i < rowCount; i++ { 1879 v1, null1 := p1.GetStrValue(i) 1880 if null1 { 1881 err := rs.AppendMustNullForBytesResult() 1882 if err != nil { 1883 return err 1884 } 1885 continue 1886 } 1887 r, err := fn(v1, v2) 1888 if err != nil { 1889 return err 1890 } 1891 1892 if err = rs.AppendMustBytesValue(r); err != nil { 1893 return err 1894 } 1895 } 1896 } else { 1897 rowCount := uint64(length) 1898 for i := uint64(0); i < rowCount; i++ { 1899 v1, _ := p1.GetStrValue(i) 1900 r, err := fn(v1, v2) 1901 if err != nil { 1902 return err 1903 } 1904 1905 if err = rs.AppendMustBytesValue(r); err != nil { 1906 return err 1907 } 1908 } 1909 } 1910 } 1911 return nil 1912 } 1913 1914 // basic case. 1915 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 1916 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1917 rowCount := uint64(length) 1918 for i := uint64(0); i < rowCount; i++ { 1919 v1, null1 := p1.GetStrValue(i) 1920 v2, null2 := p2.GetStrValue(i) 1921 if null1 || null2 { 1922 err := rs.AppendMustNullForBytesResult() 1923 if err != nil { 1924 return err 1925 } 1926 continue 1927 } 1928 r, err := fn(v1, v2) 1929 if err != nil { 1930 return err 1931 } 1932 1933 if err = rs.AppendMustBytesValue(r); err != nil { 1934 return err 1935 } 1936 } 1937 return nil 1938 } 1939 1940 rowCount := uint64(length) 1941 for i := uint64(0); i < rowCount; i++ { 1942 v1, _ := p1.GetStrValue(i) 1943 v2, _ := p2.GetStrValue(i) 1944 r, err := fn(v1, v2) 1945 if err != nil { 1946 return err 1947 } 1948 1949 if err = rs.AppendMustBytesValue(r); err != nil { 1950 return err 1951 } 1952 } 1953 return nil 1954 } 1955 1956 func compareVarlenaEqual(parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int) error { 1957 rs := vector.MustFunctionResult[bool](result) 1958 rsVec := rs.GetResultVector() 1959 rss := vector.MustFixedCol[bool](rsVec) 1960 1961 v1, v2 := parameters[0], parameters[1] 1962 if v1.IsConstNull() || v2.IsConstNull() { 1963 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 1964 return nil 1965 } 1966 col1 := vector.MustVarlenaToInt64Slice(v1) 1967 col2 := vector.MustVarlenaToInt64Slice(v2) 1968 1969 if v1.IsConst() && v2.IsConst() { 1970 ret := col1[0] == col2[0] 1971 for i := uint64(0); i < uint64(length); i++ { 1972 rss[i] = ret 1973 } 1974 return nil 1975 } 1976 1977 if !v1.IsConst() && !v2.IsConst() { 1978 for i := 0; i < length; i++ { 1979 rss[i] = col1[i] == col2[i] 1980 } 1981 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1982 } else if v1.IsConst() { 1983 for i := 0; i < length; i++ { 1984 rss[i] = col1[0] == col2[i] 1985 } 1986 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 1987 } else { 1988 for i := 0; i < length; i++ { 1989 rss[i] = col1[i] == col2[0] 1990 } 1991 nulls.Or(parameters[0].GetNulls(), rsVec.GetNulls(), rsVec.GetNulls()) 1992 } 1993 return nil 1994 } 1995 1996 func opBinaryStrStrToFixed[Tr types.FixedSizeTExceptStrType]( 1997 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 1998 arithFn func(v1, v2 string) Tr) error { 1999 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2000 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 2001 rs := vector.MustFunctionResult[Tr](result) 2002 rsVec := rs.GetResultVector() 2003 rss := vector.MustFixedCol[Tr](rsVec) 2004 2005 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 2006 if c1 && c2 { 2007 v1, null1 := p1.GetStrValue(0) 2008 v2, null2 := p2.GetStrValue(0) 2009 ifNull := null1 || null2 2010 if ifNull { 2011 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2012 } else { 2013 r := arithFn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2014 rowCount := uint64(length) 2015 for i := uint64(0); i < rowCount; i++ { 2016 rss[i] = r 2017 } 2018 } 2019 return nil 2020 } 2021 2022 if c1 { 2023 v1, null1 := p1.GetStrValue(0) 2024 if null1 { 2025 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2026 } else { 2027 x := functionUtil.QuickBytesToStr(v1) 2028 if p2.WithAnyNullValue() { 2029 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 2030 rowCount := uint64(length) 2031 for i := uint64(0); i < rowCount; i++ { 2032 v2, null2 := p2.GetStrValue(i) 2033 if null2 { 2034 continue 2035 } 2036 rss[i] = arithFn(x, functionUtil.QuickBytesToStr(v2)) 2037 } 2038 } else { 2039 rowCount := uint64(length) 2040 for i := uint64(0); i < rowCount; i++ { 2041 v2, _ := p2.GetStrValue(i) 2042 rss[i] = arithFn(x, functionUtil.QuickBytesToStr(v2)) 2043 } 2044 } 2045 } 2046 return nil 2047 } 2048 2049 if c2 { 2050 v2, null2 := p2.GetStrValue(0) 2051 if null2 { 2052 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2053 } else { 2054 y := functionUtil.QuickBytesToStr(v2) 2055 if p1.WithAnyNullValue() { 2056 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2057 rowCount := uint64(length) 2058 for i := uint64(0); i < rowCount; i++ { 2059 v1, null1 := p1.GetStrValue(i) 2060 if null1 { 2061 continue 2062 } 2063 rss[i] = arithFn(functionUtil.QuickBytesToStr(v1), y) 2064 } 2065 } else { 2066 rowCount := uint64(length) 2067 for i := uint64(0); i < rowCount; i++ { 2068 v1, _ := p1.GetStrValue(i) 2069 rss[i] = arithFn(functionUtil.QuickBytesToStr(v1), y) 2070 } 2071 } 2072 } 2073 return nil 2074 } 2075 2076 // basic case. 2077 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 2078 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 2079 rowCount := uint64(length) 2080 for i := uint64(0); i < rowCount; i++ { 2081 v1, null1 := p1.GetStrValue(i) 2082 v2, null2 := p2.GetStrValue(i) 2083 if null1 || null2 { 2084 continue 2085 } 2086 rss[i] = arithFn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2087 } 2088 return nil 2089 } 2090 2091 rowCount := uint64(length) 2092 for i := uint64(0); i < rowCount; i++ { 2093 v1, _ := p1.GetStrValue(i) 2094 v2, _ := p2.GetStrValue(i) 2095 rss[i] = arithFn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2096 } 2097 return nil 2098 } 2099 2100 func opBinaryStrStrToFixedWithErrorCheck[Tr types.FixedSizeTExceptStrType]( 2101 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2102 fn func(v1, v2 string) (Tr, error)) error { 2103 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2104 p2 := vector.GenerateFunctionStrParameter(parameters[1]) 2105 rs := vector.MustFunctionResult[Tr](result) 2106 rsVec := rs.GetResultVector() 2107 rss := vector.MustFixedCol[Tr](rsVec) 2108 2109 c1, c2 := parameters[0].IsConst(), parameters[1].IsConst() 2110 if c1 && c2 { 2111 v1, null1 := p1.GetStrValue(0) 2112 v2, null2 := p2.GetStrValue(0) 2113 ifNull := null1 || null2 2114 if ifNull { 2115 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2116 } else { 2117 r, err := fn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2118 if err != nil { 2119 return err 2120 } 2121 rowCount := uint64(length) 2122 for i := uint64(0); i < rowCount; i++ { 2123 rss[i] = r 2124 } 2125 } 2126 return nil 2127 } 2128 2129 var err error 2130 if c1 { 2131 v1, null1 := p1.GetStrValue(0) 2132 if null1 { 2133 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2134 } else { 2135 x := functionUtil.QuickBytesToStr(v1) 2136 if p2.WithAnyNullValue() { 2137 nulls.Or(rsVec.GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 2138 rowCount := uint64(length) 2139 for i := uint64(0); i < rowCount; i++ { 2140 v2, null2 := p2.GetStrValue(i) 2141 if null2 { 2142 continue 2143 } 2144 rss[i], err = fn(x, functionUtil.QuickBytesToStr(v2)) 2145 if err != nil { 2146 return err 2147 } 2148 } 2149 } else { 2150 rowCount := uint64(length) 2151 for i := uint64(0); i < rowCount; i++ { 2152 v2, _ := p2.GetStrValue(i) 2153 rss[i], err = fn(x, functionUtil.QuickBytesToStr(v2)) 2154 if err != nil { 2155 return err 2156 } 2157 } 2158 } 2159 } 2160 return nil 2161 } 2162 2163 if c2 { 2164 v2, null2 := p2.GetStrValue(0) 2165 if null2 { 2166 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2167 } else { 2168 y := functionUtil.QuickBytesToStr(v2) 2169 if p1.WithAnyNullValue() { 2170 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2171 rowCount := uint64(length) 2172 for i := uint64(0); i < rowCount; i++ { 2173 v1, null1 := p1.GetStrValue(i) 2174 if null1 { 2175 continue 2176 } 2177 rss[i], err = fn(functionUtil.QuickBytesToStr(v1), y) 2178 if err != nil { 2179 return err 2180 } 2181 } 2182 } else { 2183 rowCount := uint64(length) 2184 for i := uint64(0); i < rowCount; i++ { 2185 v1, _ := p1.GetStrValue(i) 2186 rss[i], err = fn(functionUtil.QuickBytesToStr(v1), y) 2187 if err != nil { 2188 return err 2189 } 2190 } 2191 } 2192 } 2193 return nil 2194 } 2195 2196 // basic case. 2197 if p1.WithAnyNullValue() || p2.WithAnyNullValue() { 2198 nulls.Or(parameters[0].GetNulls(), parameters[1].GetNulls(), rsVec.GetNulls()) 2199 rowCount := uint64(length) 2200 for i := uint64(0); i < rowCount; i++ { 2201 v1, null1 := p1.GetStrValue(i) 2202 v2, null2 := p2.GetStrValue(i) 2203 if null1 || null2 { 2204 continue 2205 } 2206 rss[i], err = fn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2207 if err != nil { 2208 return err 2209 } 2210 } 2211 return nil 2212 } 2213 2214 rowCount := uint64(length) 2215 for i := uint64(0); i < rowCount; i++ { 2216 v1, _ := p1.GetStrValue(i) 2217 v2, _ := p2.GetStrValue(i) 2218 rss[i], err = fn(functionUtil.QuickBytesToStr(v1), functionUtil.QuickBytesToStr(v2)) 2219 if err != nil { 2220 return err 2221 } 2222 } 2223 return nil 2224 } 2225 2226 // opUnaryFixedToFixed for unary functions whose result of f(x) is null if x is null. 2227 // and if x was not null, result will be not null. 2228 func opUnaryFixedToFixed[ 2229 T types.FixedSizeTExceptStrType, 2230 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2231 resultFn func(v T) Tr) error { 2232 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 2233 rs := vector.MustFunctionResult[Tr](result) 2234 rsVec := rs.GetResultVector() 2235 rss := vector.MustFixedCol[Tr](rsVec) 2236 2237 c1 := parameters[0].IsConst() 2238 if c1 { 2239 v1, null1 := p1.GetValue(0) 2240 if null1 { 2241 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2242 } else { 2243 r := resultFn(v1) 2244 rowCount := uint64(length) 2245 for i := uint64(0); i < rowCount; i++ { 2246 rss[i] = r 2247 } 2248 } 2249 return nil 2250 } 2251 2252 // basic case. 2253 if p1.WithAnyNullValue() { 2254 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2255 rowCount := uint64(length) 2256 for i := uint64(0); i < rowCount; i++ { 2257 v1, null1 := p1.GetValue(i) 2258 if null1 { 2259 continue 2260 } 2261 rss[i] = resultFn(v1) 2262 } 2263 return nil 2264 } 2265 2266 rowCount := uint64(length) 2267 for i := uint64(0); i < rowCount; i++ { 2268 v1, _ := p1.GetValue(i) 2269 rss[i] = resultFn(v1) 2270 } 2271 return nil 2272 } 2273 2274 func opUnaryBytesToFixed[ 2275 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2276 resultFn func(v []byte) Tr) error { 2277 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2278 rs := vector.MustFunctionResult[Tr](result) 2279 rsVec := rs.GetResultVector() 2280 rss := vector.MustFixedCol[Tr](rsVec) 2281 2282 c1 := parameters[0].IsConst() 2283 if c1 { 2284 v1, null1 := p1.GetStrValue(0) 2285 if null1 { 2286 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2287 } else { 2288 r := resultFn(v1) 2289 rowCount := uint64(length) 2290 for i := uint64(0); i < rowCount; i++ { 2291 rss[i] = r 2292 } 2293 } 2294 return nil 2295 } 2296 2297 // basic case. 2298 if p1.WithAnyNullValue() { 2299 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2300 rowCount := uint64(length) 2301 for i := uint64(0); i < rowCount; i++ { 2302 v1, null1 := p1.GetStrValue(i) 2303 if null1 { 2304 continue 2305 } 2306 rss[i] = resultFn(v1) 2307 } 2308 return nil 2309 } 2310 2311 rowCount := uint64(length) 2312 for i := uint64(0); i < rowCount; i++ { 2313 v1, _ := p1.GetStrValue(i) 2314 rss[i] = resultFn(v1) 2315 } 2316 return nil 2317 } 2318 2319 func opUnaryStrToFixed[ 2320 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2321 resultFn func(v string) Tr) error { 2322 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2323 rs := vector.MustFunctionResult[Tr](result) 2324 rsVec := rs.GetResultVector() 2325 rss := vector.MustFixedCol[Tr](rsVec) 2326 2327 c1 := parameters[0].IsConst() 2328 if c1 { 2329 v1, null1 := p1.GetStrValue(0) 2330 if null1 { 2331 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2332 } else { 2333 r := resultFn(functionUtil.QuickBytesToStr(v1)) 2334 rowCount := uint64(length) 2335 for i := uint64(0); i < rowCount; i++ { 2336 rss[i] = r 2337 } 2338 } 2339 return nil 2340 } 2341 2342 // basic case. 2343 if p1.WithAnyNullValue() { 2344 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2345 rowCount := uint64(length) 2346 for i := uint64(0); i < rowCount; i++ { 2347 v1, null1 := p1.GetStrValue(i) 2348 if null1 { 2349 continue 2350 } 2351 rss[i] = resultFn(functionUtil.QuickBytesToStr(v1)) 2352 } 2353 return nil 2354 } 2355 2356 rowCount := uint64(length) 2357 for i := uint64(0); i < rowCount; i++ { 2358 v1, _ := p1.GetStrValue(i) 2359 rss[i] = resultFn(functionUtil.QuickBytesToStr(v1)) 2360 } 2361 return nil 2362 } 2363 2364 func opUnaryBytesToBytes( 2365 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2366 resultFn func(v []byte) []byte) error { 2367 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2368 rs := vector.MustFunctionResult[types.Varlena](result) 2369 rsVec := rs.GetResultVector() 2370 2371 c1 := parameters[0].IsConst() 2372 if c1 { 2373 v1, null1 := p1.GetStrValue(0) 2374 if null1 { 2375 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2376 } else { 2377 r := resultFn(v1) 2378 2379 rowCount := uint64(length) 2380 for i := uint64(0); i < rowCount; i++ { 2381 if err := rs.AppendMustBytesValue(r); err != nil { 2382 return err 2383 } 2384 } 2385 } 2386 return nil 2387 } 2388 2389 // basic case. 2390 if p1.WithAnyNullValue() { 2391 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2392 rowCount := uint64(length) 2393 for i := uint64(0); i < rowCount; i++ { 2394 v1, null1 := p1.GetStrValue(i) 2395 if null1 { 2396 if err := rs.AppendMustNullForBytesResult(); err != nil { 2397 return err 2398 } 2399 } else { 2400 r := resultFn(v1) 2401 if err := rs.AppendMustBytesValue(r); err != nil { 2402 return err 2403 } 2404 } 2405 } 2406 return nil 2407 } 2408 2409 rowCount := uint64(length) 2410 for i := uint64(0); i < rowCount; i++ { 2411 v1, _ := p1.GetStrValue(i) 2412 r := resultFn(v1) 2413 if err := rs.AppendMustBytesValue(r); err != nil { 2414 return err 2415 } 2416 } 2417 return nil 2418 } 2419 2420 func opUnaryBytesToStr( 2421 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2422 resultFn func(v []byte) string) error { 2423 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2424 rs := vector.MustFunctionResult[types.Varlena](result) 2425 rsVec := rs.GetResultVector() 2426 2427 c1 := parameters[0].IsConst() 2428 if c1 { 2429 v1, null1 := p1.GetStrValue(0) 2430 if null1 { 2431 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2432 } else { 2433 r := resultFn(v1) 2434 2435 rowCount := uint64(length) 2436 for i := uint64(0); i < rowCount; i++ { 2437 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2438 return err 2439 } 2440 } 2441 } 2442 return nil 2443 } 2444 2445 // basic case. 2446 if p1.WithAnyNullValue() { 2447 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2448 rowCount := uint64(length) 2449 for i := uint64(0); i < rowCount; i++ { 2450 v1, null1 := p1.GetStrValue(i) 2451 if null1 { 2452 if err := rs.AppendMustNullForBytesResult(); err != nil { 2453 return err 2454 } 2455 } else { 2456 r := resultFn(v1) 2457 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2458 return err 2459 } 2460 } 2461 } 2462 return nil 2463 } 2464 2465 rowCount := uint64(length) 2466 for i := uint64(0); i < rowCount; i++ { 2467 v1, _ := p1.GetStrValue(i) 2468 r := resultFn(v1) 2469 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2470 return err 2471 } 2472 } 2473 return nil 2474 } 2475 2476 func opUnaryStrToStr( 2477 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2478 resultFn func(v string) string) error { 2479 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2480 rs := vector.MustFunctionResult[types.Varlena](result) 2481 rsVec := rs.GetResultVector() 2482 2483 c1 := parameters[0].IsConst() 2484 if c1 { 2485 v1, null1 := p1.GetStrValue(0) 2486 if null1 { 2487 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2488 } else { 2489 r := resultFn(functionUtil.QuickBytesToStr(v1)) 2490 2491 rowCount := uint64(length) 2492 for i := uint64(0); i < rowCount; i++ { 2493 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2494 return err 2495 } 2496 } 2497 } 2498 return nil 2499 } 2500 2501 // basic case. 2502 if p1.WithAnyNullValue() { 2503 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2504 rowCount := uint64(length) 2505 for i := uint64(0); i < rowCount; i++ { 2506 v1, null1 := p1.GetStrValue(i) 2507 if null1 { 2508 if err := rs.AppendMustNullForBytesResult(); err != nil { 2509 return err 2510 } 2511 } else { 2512 r := resultFn(functionUtil.QuickBytesToStr(v1)) 2513 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2514 return err 2515 } 2516 } 2517 } 2518 return nil 2519 } 2520 2521 rowCount := uint64(length) 2522 for i := uint64(0); i < rowCount; i++ { 2523 v1, _ := p1.GetStrValue(i) 2524 r := resultFn(functionUtil.QuickBytesToStr(v1)) 2525 if err := rs.AppendMustBytesValue(functionUtil.QuickStrToBytes(r)); err != nil { 2526 return err 2527 } 2528 } 2529 return nil 2530 } 2531 2532 func opUnaryFixedToStr[ 2533 T types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2534 resultFn func(v T) string) error { 2535 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 2536 rs := vector.MustFunctionResult[types.Varlena](result) 2537 rsVec := rs.GetResultVector() 2538 2539 c1 := parameters[0].IsConst() 2540 if c1 { 2541 v1, null1 := p1.GetValue(0) 2542 if null1 { 2543 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2544 } else { 2545 rb := resultFn(v1) 2546 r := functionUtil.QuickStrToBytes(rb) 2547 2548 rowCount := uint64(length) 2549 for i := uint64(0); i < rowCount; i++ { 2550 if err := rs.AppendMustBytesValue(r); err != nil { 2551 return err 2552 } 2553 } 2554 } 2555 return nil 2556 } 2557 2558 // basic case. 2559 if p1.WithAnyNullValue() { 2560 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2561 rowCount := uint64(length) 2562 for i := uint64(0); i < rowCount; i++ { 2563 v1, null1 := p1.GetValue(i) 2564 if null1 { 2565 if err := rs.AppendMustNullForBytesResult(); err != nil { 2566 return err 2567 } 2568 } else { 2569 rb := resultFn(v1) 2570 r := functionUtil.QuickStrToBytes(rb) 2571 if err := rs.AppendMustBytesValue(r); err != nil { 2572 return err 2573 } 2574 } 2575 } 2576 return nil 2577 } 2578 2579 rowCount := uint64(length) 2580 for i := uint64(0); i < rowCount; i++ { 2581 v1, _ := p1.GetValue(i) 2582 rb := resultFn(v1) 2583 r := functionUtil.QuickStrToBytes(rb) 2584 if err := rs.AppendMustBytesValue(r); err != nil { 2585 return err 2586 } 2587 } 2588 return nil 2589 } 2590 2591 func opUnaryFixedToStrWithErrorCheck[ 2592 T types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2593 resultFn func(v T) (string, error)) error { 2594 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 2595 rs := vector.MustFunctionResult[types.Varlena](result) 2596 rsVec := rs.GetResultVector() 2597 2598 c1 := parameters[0].IsConst() 2599 if c1 { 2600 v1, null1 := p1.GetValue(0) 2601 if null1 { 2602 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2603 } else { 2604 rb, err := resultFn(v1) 2605 if err != nil { 2606 return err 2607 } 2608 r := functionUtil.QuickStrToBytes(rb) 2609 2610 rowCount := uint64(length) 2611 for i := uint64(0); i < rowCount; i++ { 2612 if err = rs.AppendMustBytesValue(r); err != nil { 2613 return err 2614 } 2615 } 2616 } 2617 return nil 2618 } 2619 2620 // basic case. 2621 if p1.WithAnyNullValue() { 2622 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2623 rowCount := uint64(length) 2624 for i := uint64(0); i < rowCount; i++ { 2625 v1, null1 := p1.GetValue(i) 2626 if null1 { 2627 if err := rs.AppendMustNullForBytesResult(); err != nil { 2628 return err 2629 } 2630 } else { 2631 rb, err := resultFn(v1) 2632 if err != nil { 2633 return err 2634 } 2635 r := functionUtil.QuickStrToBytes(rb) 2636 if err = rs.AppendMustBytesValue(r); err != nil { 2637 return err 2638 } 2639 } 2640 } 2641 return nil 2642 } 2643 2644 rowCount := uint64(length) 2645 for i := uint64(0); i < rowCount; i++ { 2646 v1, _ := p1.GetValue(i) 2647 rb, err := resultFn(v1) 2648 if err != nil { 2649 return err 2650 } 2651 r := functionUtil.QuickStrToBytes(rb) 2652 if err = rs.AppendMustBytesValue(r); err != nil { 2653 return err 2654 } 2655 } 2656 return nil 2657 } 2658 2659 func opUnaryStrToBytesWithErrorCheck( 2660 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2661 resultFn func(v string) ([]byte, error)) error { 2662 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2663 rs := vector.MustFunctionResult[types.Varlena](result) 2664 rsVec := rs.GetResultVector() 2665 2666 c1 := parameters[0].IsConst() 2667 if c1 { 2668 v1, null1 := p1.GetStrValue(0) 2669 if null1 { 2670 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2671 } else { 2672 r, err := resultFn(functionUtil.QuickBytesToStr(v1)) 2673 if err != nil { 2674 return err 2675 } 2676 2677 rowCount := uint64(length) 2678 for i := uint64(0); i < rowCount; i++ { 2679 if err = rs.AppendMustBytesValue(r); err != nil { 2680 return err 2681 } 2682 } 2683 } 2684 return nil 2685 } 2686 2687 // basic case. 2688 if p1.WithAnyNullValue() { 2689 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2690 rowCount := uint64(length) 2691 for i := uint64(0); i < rowCount; i++ { 2692 v1, null1 := p1.GetStrValue(i) 2693 if null1 { 2694 if err := rs.AppendMustNullForBytesResult(); err != nil { 2695 return err 2696 } 2697 } else { 2698 r, err := resultFn(functionUtil.QuickBytesToStr(v1)) 2699 if err != nil { 2700 return err 2701 } 2702 if err = rs.AppendMustBytesValue(r); err != nil { 2703 return err 2704 } 2705 } 2706 } 2707 return nil 2708 } 2709 2710 rowCount := uint64(length) 2711 for i := uint64(0); i < rowCount; i++ { 2712 v1, _ := p1.GetStrValue(i) 2713 r, err := resultFn(functionUtil.QuickBytesToStr(v1)) 2714 if err != nil { 2715 return err 2716 } 2717 if err = rs.AppendMustBytesValue(r); err != nil { 2718 return err 2719 } 2720 } 2721 return nil 2722 } 2723 2724 func opUnaryBytesToBytesWithErrorCheck( 2725 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2726 resultFn func(v []byte) ([]byte, error)) error { 2727 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2728 rs := vector.MustFunctionResult[types.Varlena](result) 2729 rsVec := rs.GetResultVector() 2730 2731 c1 := parameters[0].IsConst() 2732 if c1 { 2733 v1, null1 := p1.GetStrValue(0) 2734 if null1 { 2735 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2736 } else { 2737 r, err := resultFn(v1) 2738 if err != nil { 2739 return err 2740 } 2741 2742 rowCount := uint64(length) 2743 for i := uint64(0); i < rowCount; i++ { 2744 if err = rs.AppendMustBytesValue(r); err != nil { 2745 return err 2746 } 2747 } 2748 } 2749 return nil 2750 } 2751 2752 // basic case. 2753 if p1.WithAnyNullValue() { 2754 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2755 rowCount := uint64(length) 2756 for i := uint64(0); i < rowCount; i++ { 2757 v1, null1 := p1.GetStrValue(i) 2758 if null1 { 2759 if err := rs.AppendMustNullForBytesResult(); err != nil { 2760 return err 2761 } 2762 } else { 2763 r, err := resultFn(v1) 2764 if err != nil { 2765 return err 2766 } 2767 if err = rs.AppendMustBytesValue(r); err != nil { 2768 return err 2769 } 2770 } 2771 } 2772 return nil 2773 } 2774 2775 rowCount := uint64(length) 2776 for i := uint64(0); i < rowCount; i++ { 2777 v1, _ := p1.GetStrValue(i) 2778 r, err := resultFn(v1) 2779 if err != nil { 2780 return err 2781 } 2782 if err = rs.AppendMustBytesValue(r); err != nil { 2783 return err 2784 } 2785 } 2786 return nil 2787 } 2788 2789 func opUnaryBytesToStrWithErrorCheck( 2790 parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2791 resultFn func(v []byte) (string, error)) error { 2792 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2793 rs := vector.MustFunctionResult[types.Varlena](result) 2794 rsVec := rs.GetResultVector() 2795 2796 c1 := parameters[0].IsConst() 2797 if c1 { 2798 v1, null1 := p1.GetStrValue(0) 2799 if null1 { 2800 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2801 } else { 2802 rb, err := resultFn(v1) 2803 if err != nil { 2804 return err 2805 } 2806 r := functionUtil.QuickStrToBytes(rb) 2807 rowCount := uint64(length) 2808 for i := uint64(0); i < rowCount; i++ { 2809 if err = rs.AppendMustBytesValue(r); err != nil { 2810 return err 2811 } 2812 } 2813 } 2814 return nil 2815 } 2816 2817 // basic case. 2818 if p1.WithAnyNullValue() { 2819 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2820 rowCount := uint64(length) 2821 for i := uint64(0); i < rowCount; i++ { 2822 v1, null1 := p1.GetStrValue(i) 2823 if null1 { 2824 if err := rs.AppendMustNullForBytesResult(); err != nil { 2825 return err 2826 } 2827 } else { 2828 rb, err := resultFn(v1) 2829 if err != nil { 2830 return err 2831 } 2832 r := functionUtil.QuickStrToBytes(rb) 2833 if err = rs.AppendMustBytesValue(r); err != nil { 2834 return err 2835 } 2836 } 2837 } 2838 return nil 2839 } 2840 2841 rowCount := uint64(length) 2842 for i := uint64(0); i < rowCount; i++ { 2843 v1, _ := p1.GetStrValue(i) 2844 rb, err := resultFn(v1) 2845 if err != nil { 2846 return err 2847 } 2848 r := functionUtil.QuickStrToBytes(rb) 2849 if err = rs.AppendMustBytesValue(r); err != nil { 2850 return err 2851 } 2852 } 2853 return nil 2854 } 2855 2856 func opUnaryFixedToFixedWithErrorCheck[ 2857 T types.FixedSizeTExceptStrType, 2858 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2859 resultFn func(v T) (Tr, error)) error { 2860 p1 := vector.GenerateFunctionFixedTypeParameter[T](parameters[0]) 2861 rs := vector.MustFunctionResult[Tr](result) 2862 rsVec := rs.GetResultVector() 2863 rss := vector.MustFixedCol[Tr](rsVec) 2864 2865 c1 := parameters[0].IsConst() 2866 if c1 { 2867 v1, null1 := p1.GetValue(0) 2868 if null1 { 2869 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2870 } else { 2871 r, err := resultFn(v1) 2872 if err != nil { 2873 return err 2874 } 2875 rowCount := uint64(length) 2876 for i := uint64(0); i < rowCount; i++ { 2877 rss[i] = r 2878 } 2879 } 2880 return nil 2881 } 2882 2883 // basic case. 2884 var err error 2885 if p1.WithAnyNullValue() { 2886 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2887 rowCount := uint64(length) 2888 for i := uint64(0); i < rowCount; i++ { 2889 v1, null1 := p1.GetValue(i) 2890 if null1 { 2891 continue 2892 } 2893 rss[i], err = resultFn(v1) 2894 if err != nil { 2895 return err 2896 } 2897 } 2898 return nil 2899 } 2900 2901 rowCount := uint64(length) 2902 for i := uint64(0); i < rowCount; i++ { 2903 v1, _ := p1.GetValue(i) 2904 rss[i], err = resultFn(v1) 2905 if err != nil { 2906 return err 2907 } 2908 } 2909 return nil 2910 } 2911 2912 func opUnaryBytesToFixedWithErrorCheck[ 2913 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2914 resultFn func(v []byte) (Tr, error)) error { 2915 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2916 rs := vector.MustFunctionResult[Tr](result) 2917 rsVec := rs.GetResultVector() 2918 rss := vector.MustFixedCol[Tr](rsVec) 2919 2920 c1 := parameters[0].IsConst() 2921 if c1 { 2922 v1, null1 := p1.GetStrValue(0) 2923 if null1 { 2924 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2925 } else { 2926 r, err := resultFn(v1) 2927 if err != nil { 2928 return err 2929 } 2930 rowCount := uint64(length) 2931 for i := uint64(0); i < rowCount; i++ { 2932 rss[i] = r 2933 } 2934 } 2935 return nil 2936 } 2937 2938 // basic case. 2939 var err error 2940 if p1.WithAnyNullValue() { 2941 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2942 rowCount := uint64(length) 2943 for i := uint64(0); i < rowCount; i++ { 2944 v1, null1 := p1.GetStrValue(i) 2945 if null1 { 2946 continue 2947 } 2948 rss[i], err = resultFn(v1) 2949 if err != nil { 2950 return err 2951 } 2952 } 2953 return nil 2954 } 2955 2956 rowCount := uint64(length) 2957 for i := uint64(0); i < rowCount; i++ { 2958 v1, _ := p1.GetStrValue(i) 2959 rss[i], err = resultFn(v1) 2960 if err != nil { 2961 return err 2962 } 2963 } 2964 return nil 2965 } 2966 2967 func opUnaryStrToFixedWithErrorCheck[ 2968 Tr types.FixedSizeTExceptStrType](parameters []*vector.Vector, result vector.FunctionResultWrapper, _ *process.Process, length int, 2969 resultFn func(v string) (Tr, error)) error { 2970 p1 := vector.GenerateFunctionStrParameter(parameters[0]) 2971 rs := vector.MustFunctionResult[Tr](result) 2972 rsVec := rs.GetResultVector() 2973 rss := vector.MustFixedCol[Tr](rsVec) 2974 2975 c1 := parameters[0].IsConst() 2976 if c1 { 2977 v1, null1 := p1.GetStrValue(0) 2978 if null1 { 2979 nulls.AddRange(rsVec.GetNulls(), 0, uint64(length)) 2980 } else { 2981 r, err := resultFn(functionUtil.QuickBytesToStr(v1)) 2982 if err != nil { 2983 return err 2984 } 2985 rowCount := uint64(length) 2986 for i := uint64(0); i < rowCount; i++ { 2987 rss[i] = r 2988 } 2989 } 2990 return nil 2991 } 2992 2993 // basic case. 2994 var err error 2995 if p1.WithAnyNullValue() { 2996 nulls.Or(rsVec.GetNulls(), parameters[0].GetNulls(), rsVec.GetNulls()) 2997 rowCount := uint64(length) 2998 for i := uint64(0); i < rowCount; i++ { 2999 v1, null1 := p1.GetStrValue(i) 3000 if null1 { 3001 continue 3002 } 3003 rss[i], err = resultFn(functionUtil.QuickBytesToStr(v1)) 3004 if err != nil { 3005 return err 3006 } 3007 } 3008 return nil 3009 } 3010 3011 rowCount := uint64(length) 3012 for i := uint64(0); i < rowCount; i++ { 3013 v1, _ := p1.GetStrValue(i) 3014 rss[i], err = resultFn(functionUtil.QuickBytesToStr(v1)) 3015 if err != nil { 3016 return err 3017 } 3018 } 3019 return nil 3020 } 3021 3022 func opNoneParamToFixed[Tr types.FixedSizeTExceptStrType]( 3023 result vector.FunctionResultWrapper, proc *process.Process, length int, resultFn func() Tr) error { 3024 rs := vector.MustFunctionResult[Tr](result) 3025 rsVec := rs.GetResultVector() 3026 rss := vector.MustFixedCol[Tr](rsVec) 3027 3028 for i := 0; i < length; i++ { 3029 rss[i] = resultFn() 3030 } 3031 return nil 3032 } 3033 3034 func opNoneParamToBytes( 3035 result vector.FunctionResultWrapper, proc *process.Process, length int, resultFn func() []byte) error { 3036 rs := vector.MustFunctionResult[types.Varlena](result) 3037 3038 for i := 0; i < length; i++ { 3039 if err := rs.AppendMustBytesValue(resultFn()); err != nil { 3040 return err 3041 } 3042 } 3043 return nil 3044 } 3045 3046 func opNoneParamToBytesWithErrorCheck( 3047 result vector.FunctionResultWrapper, proc *process.Process, length int, resultFn func() ([]byte, error)) error { 3048 rs := vector.MustFunctionResult[types.Varlena](result) 3049 3050 for i := 0; i < length; i++ { 3051 r, err := resultFn() 3052 if err != nil { 3053 return err 3054 } 3055 if err = rs.AppendMustBytesValue(r); err != nil { 3056 return err 3057 } 3058 } 3059 return nil 3060 }