github.com/whtcorpsinc/milevadb-prod@v0.0.0-20211104133533-f57f4be3b597/dbs/memristed/memex/builtin_control_vec_generated.go (about) 1 // Copyright 2020 WHTCORPS INC, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 // Code generated by go generate in memex/generator; DO NOT EDIT. 15 16 package memex 17 18 import ( 19 "time" 20 21 "github.com/whtcorpsinc/milevadb/types" 22 "github.com/whtcorpsinc/milevadb/soliton/chunk" 23 ) 24 25 // NOTE: Control memexs optionally evaluate some branches depending on conditions, but vectorization executes all 26 // branches, during which the unnecessary branches may return errors or warnings. To avoid this case, when branches 27 // meet errors or warnings, the vectorization falls back the scalar execution. 28 29 func (b *builtinCaseWhenIntSig) fallbackEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 30 n := input.NumEvents() 31 result.ResizeInt64(n, false) 32 x := result.Int64s() 33 for i := 0; i < n; i++ { 34 res, isNull, err := b.evalInt(input.GetEvent(i)) 35 if err != nil { 36 return err 37 } 38 result.SetNull(i, isNull) 39 if isNull { 40 continue 41 } 42 43 x[i] = res 44 45 } 46 return nil 47 } 48 49 func (b *builtinCaseWhenIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 50 n := input.NumEvents() 51 args, l := b.getArgs(), len(b.getArgs()) 52 whens := make([]*chunk.DeferredCauset, l/2) 53 whensSlice := make([][]int64, l/2) 54 thens := make([]*chunk.DeferredCauset, l/2) 55 var eLse *chunk.DeferredCauset 56 thensSlice := make([][]int64, l/2) 57 var eLseSlice []int64 58 sc := b.ctx.GetStochastikVars().StmtCtx 59 beforeWarns := sc.WarningCount() 60 61 for j := 0; j < l-1; j += 2 { 62 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 63 if err != nil { 64 return err 65 } 66 defer b.bufSlabPredictor.put(bufWhen) 67 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 68 afterWarns := sc.WarningCount() 69 if err != nil || afterWarns > beforeWarns { 70 if afterWarns > beforeWarns { 71 sc.TruncateWarnings(int(beforeWarns)) 72 } 73 return b.fallbackEvalInt(input, result) 74 } 75 whens[j/2] = bufWhen 76 whensSlice[j/2] = bufWhen.Int64s() 77 78 bufThen, err := b.bufSlabPredictor.get(types.ETInt, n) 79 if err != nil { 80 return err 81 } 82 defer b.bufSlabPredictor.put(bufThen) 83 err = args[j+1].VecEvalInt(b.ctx, input, bufThen) 84 afterWarns = sc.WarningCount() 85 if err != nil || afterWarns > beforeWarns { 86 if afterWarns > beforeWarns { 87 sc.TruncateWarnings(int(beforeWarns)) 88 } 89 return b.fallbackEvalInt(input, result) 90 } 91 thens[j/2] = bufThen 92 thensSlice[j/2] = bufThen.Int64s() 93 } 94 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 95 // else clause -> args[l-1] 96 // If case clause has else clause, l%2 == 1. 97 if l%2 == 1 { 98 bufElse, err := b.bufSlabPredictor.get(types.ETInt, n) 99 if err != nil { 100 return err 101 } 102 defer b.bufSlabPredictor.put(bufElse) 103 err = args[l-1].VecEvalInt(b.ctx, input, bufElse) 104 afterWarns := sc.WarningCount() 105 if err != nil || afterWarns > beforeWarns { 106 if afterWarns > beforeWarns { 107 sc.TruncateWarnings(int(beforeWarns)) 108 } 109 return b.fallbackEvalInt(input, result) 110 } 111 eLse = bufElse 112 eLseSlice = bufElse.Int64s() 113 } 114 result.ResizeInt64(n, false) 115 resultSlice := result.Int64s() 116 ROW: 117 for i := 0; i < n; i++ { 118 for j := 0; j < l/2; j++ { 119 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 120 continue 121 } 122 resultSlice[i] = thensSlice[j][i] 123 result.SetNull(i, thens[j].IsNull(i)) 124 continue ROW 125 } 126 if eLse != nil { 127 resultSlice[i] = eLseSlice[i] 128 result.SetNull(i, eLse.IsNull(i)) 129 } else { 130 result.SetNull(i, true) 131 } 132 } 133 return nil 134 } 135 136 func (b *builtinCaseWhenIntSig) vectorized() bool { 137 return true 138 } 139 140 func (b *builtinCaseWhenRealSig) fallbackEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 141 n := input.NumEvents() 142 result.ResizeFloat64(n, false) 143 x := result.Float64s() 144 for i := 0; i < n; i++ { 145 res, isNull, err := b.evalReal(input.GetEvent(i)) 146 if err != nil { 147 return err 148 } 149 result.SetNull(i, isNull) 150 if isNull { 151 continue 152 } 153 154 x[i] = res 155 156 } 157 return nil 158 } 159 160 func (b *builtinCaseWhenRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 161 n := input.NumEvents() 162 args, l := b.getArgs(), len(b.getArgs()) 163 whens := make([]*chunk.DeferredCauset, l/2) 164 whensSlice := make([][]int64, l/2) 165 thens := make([]*chunk.DeferredCauset, l/2) 166 var eLse *chunk.DeferredCauset 167 thensSlice := make([][]float64, l/2) 168 var eLseSlice []float64 169 sc := b.ctx.GetStochastikVars().StmtCtx 170 beforeWarns := sc.WarningCount() 171 172 for j := 0; j < l-1; j += 2 { 173 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 174 if err != nil { 175 return err 176 } 177 defer b.bufSlabPredictor.put(bufWhen) 178 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 179 afterWarns := sc.WarningCount() 180 if err != nil || afterWarns > beforeWarns { 181 if afterWarns > beforeWarns { 182 sc.TruncateWarnings(int(beforeWarns)) 183 } 184 return b.fallbackEvalReal(input, result) 185 } 186 whens[j/2] = bufWhen 187 whensSlice[j/2] = bufWhen.Int64s() 188 189 bufThen, err := b.bufSlabPredictor.get(types.ETReal, n) 190 if err != nil { 191 return err 192 } 193 defer b.bufSlabPredictor.put(bufThen) 194 err = args[j+1].VecEvalReal(b.ctx, input, bufThen) 195 afterWarns = sc.WarningCount() 196 if err != nil || afterWarns > beforeWarns { 197 if afterWarns > beforeWarns { 198 sc.TruncateWarnings(int(beforeWarns)) 199 } 200 return b.fallbackEvalReal(input, result) 201 } 202 thens[j/2] = bufThen 203 thensSlice[j/2] = bufThen.Float64s() 204 } 205 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 206 // else clause -> args[l-1] 207 // If case clause has else clause, l%2 == 1. 208 if l%2 == 1 { 209 bufElse, err := b.bufSlabPredictor.get(types.ETReal, n) 210 if err != nil { 211 return err 212 } 213 defer b.bufSlabPredictor.put(bufElse) 214 err = args[l-1].VecEvalReal(b.ctx, input, bufElse) 215 afterWarns := sc.WarningCount() 216 if err != nil || afterWarns > beforeWarns { 217 if afterWarns > beforeWarns { 218 sc.TruncateWarnings(int(beforeWarns)) 219 } 220 return b.fallbackEvalReal(input, result) 221 } 222 eLse = bufElse 223 eLseSlice = bufElse.Float64s() 224 } 225 result.ResizeFloat64(n, false) 226 resultSlice := result.Float64s() 227 ROW: 228 for i := 0; i < n; i++ { 229 for j := 0; j < l/2; j++ { 230 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 231 continue 232 } 233 resultSlice[i] = thensSlice[j][i] 234 result.SetNull(i, thens[j].IsNull(i)) 235 continue ROW 236 } 237 if eLse != nil { 238 resultSlice[i] = eLseSlice[i] 239 result.SetNull(i, eLse.IsNull(i)) 240 } else { 241 result.SetNull(i, true) 242 } 243 } 244 return nil 245 } 246 247 func (b *builtinCaseWhenRealSig) vectorized() bool { 248 return true 249 } 250 251 func (b *builtinCaseWhenDecimalSig) fallbackEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 252 n := input.NumEvents() 253 result.ResizeDecimal(n, false) 254 x := result.Decimals() 255 for i := 0; i < n; i++ { 256 res, isNull, err := b.evalDecimal(input.GetEvent(i)) 257 if err != nil { 258 return err 259 } 260 result.SetNull(i, isNull) 261 if isNull { 262 continue 263 } 264 265 x[i] = *res 266 267 } 268 return nil 269 } 270 271 func (b *builtinCaseWhenDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 272 n := input.NumEvents() 273 args, l := b.getArgs(), len(b.getArgs()) 274 whens := make([]*chunk.DeferredCauset, l/2) 275 whensSlice := make([][]int64, l/2) 276 thens := make([]*chunk.DeferredCauset, l/2) 277 var eLse *chunk.DeferredCauset 278 thensSlice := make([][]types.MyDecimal, l/2) 279 var eLseSlice []types.MyDecimal 280 sc := b.ctx.GetStochastikVars().StmtCtx 281 beforeWarns := sc.WarningCount() 282 283 for j := 0; j < l-1; j += 2 { 284 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 285 if err != nil { 286 return err 287 } 288 defer b.bufSlabPredictor.put(bufWhen) 289 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 290 afterWarns := sc.WarningCount() 291 if err != nil || afterWarns > beforeWarns { 292 if afterWarns > beforeWarns { 293 sc.TruncateWarnings(int(beforeWarns)) 294 } 295 return b.fallbackEvalDecimal(input, result) 296 } 297 whens[j/2] = bufWhen 298 whensSlice[j/2] = bufWhen.Int64s() 299 300 bufThen, err := b.bufSlabPredictor.get(types.ETDecimal, n) 301 if err != nil { 302 return err 303 } 304 defer b.bufSlabPredictor.put(bufThen) 305 err = args[j+1].VecEvalDecimal(b.ctx, input, bufThen) 306 afterWarns = sc.WarningCount() 307 if err != nil || afterWarns > beforeWarns { 308 if afterWarns > beforeWarns { 309 sc.TruncateWarnings(int(beforeWarns)) 310 } 311 return b.fallbackEvalDecimal(input, result) 312 } 313 thens[j/2] = bufThen 314 thensSlice[j/2] = bufThen.Decimals() 315 } 316 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 317 // else clause -> args[l-1] 318 // If case clause has else clause, l%2 == 1. 319 if l%2 == 1 { 320 bufElse, err := b.bufSlabPredictor.get(types.ETDecimal, n) 321 if err != nil { 322 return err 323 } 324 defer b.bufSlabPredictor.put(bufElse) 325 err = args[l-1].VecEvalDecimal(b.ctx, input, bufElse) 326 afterWarns := sc.WarningCount() 327 if err != nil || afterWarns > beforeWarns { 328 if afterWarns > beforeWarns { 329 sc.TruncateWarnings(int(beforeWarns)) 330 } 331 return b.fallbackEvalDecimal(input, result) 332 } 333 eLse = bufElse 334 eLseSlice = bufElse.Decimals() 335 } 336 result.ResizeDecimal(n, false) 337 resultSlice := result.Decimals() 338 ROW: 339 for i := 0; i < n; i++ { 340 for j := 0; j < l/2; j++ { 341 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 342 continue 343 } 344 resultSlice[i] = thensSlice[j][i] 345 result.SetNull(i, thens[j].IsNull(i)) 346 continue ROW 347 } 348 if eLse != nil { 349 resultSlice[i] = eLseSlice[i] 350 result.SetNull(i, eLse.IsNull(i)) 351 } else { 352 result.SetNull(i, true) 353 } 354 } 355 return nil 356 } 357 358 func (b *builtinCaseWhenDecimalSig) vectorized() bool { 359 return true 360 } 361 362 func (b *builtinCaseWhenStringSig) fallbackEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 363 n := input.NumEvents() 364 result.ReserveString(n) 365 for i := 0; i < n; i++ { 366 res, isNull, err := b.evalString(input.GetEvent(i)) 367 if err != nil { 368 return err 369 } 370 if isNull { 371 result.AppendNull() 372 continue 373 } 374 result.AppendString(res) 375 } 376 return nil 377 } 378 379 func (b *builtinCaseWhenStringSig) vecEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 380 n := input.NumEvents() 381 args, l := b.getArgs(), len(b.getArgs()) 382 whens := make([]*chunk.DeferredCauset, l/2) 383 whensSlice := make([][]int64, l/2) 384 thens := make([]*chunk.DeferredCauset, l/2) 385 var eLse *chunk.DeferredCauset 386 sc := b.ctx.GetStochastikVars().StmtCtx 387 beforeWarns := sc.WarningCount() 388 389 for j := 0; j < l-1; j += 2 { 390 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 391 if err != nil { 392 return err 393 } 394 defer b.bufSlabPredictor.put(bufWhen) 395 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 396 afterWarns := sc.WarningCount() 397 if err != nil || afterWarns > beforeWarns { 398 if afterWarns > beforeWarns { 399 sc.TruncateWarnings(int(beforeWarns)) 400 } 401 return b.fallbackEvalString(input, result) 402 } 403 whens[j/2] = bufWhen 404 whensSlice[j/2] = bufWhen.Int64s() 405 406 bufThen, err := b.bufSlabPredictor.get(types.ETString, n) 407 if err != nil { 408 return err 409 } 410 defer b.bufSlabPredictor.put(bufThen) 411 err = args[j+1].VecEvalString(b.ctx, input, bufThen) 412 afterWarns = sc.WarningCount() 413 if err != nil || afterWarns > beforeWarns { 414 if afterWarns > beforeWarns { 415 sc.TruncateWarnings(int(beforeWarns)) 416 } 417 return b.fallbackEvalString(input, result) 418 } 419 thens[j/2] = bufThen 420 } 421 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 422 // else clause -> args[l-1] 423 // If case clause has else clause, l%2 == 1. 424 if l%2 == 1 { 425 bufElse, err := b.bufSlabPredictor.get(types.ETString, n) 426 if err != nil { 427 return err 428 } 429 defer b.bufSlabPredictor.put(bufElse) 430 err = args[l-1].VecEvalString(b.ctx, input, bufElse) 431 afterWarns := sc.WarningCount() 432 if err != nil || afterWarns > beforeWarns { 433 if afterWarns > beforeWarns { 434 sc.TruncateWarnings(int(beforeWarns)) 435 } 436 return b.fallbackEvalString(input, result) 437 } 438 eLse = bufElse 439 } 440 result.ReserveString(n) 441 ROW: 442 for i := 0; i < n; i++ { 443 for j := 0; j < l/2; j++ { 444 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 445 continue 446 } 447 if thens[j].IsNull(i) { 448 result.AppendNull() 449 } else { 450 result.AppendString(thens[j].GetString(i)) 451 } 452 continue ROW 453 } 454 if eLse != nil { 455 if eLse.IsNull(i) { 456 result.AppendNull() 457 } else { 458 result.AppendString(eLse.GetString(i)) 459 } 460 } else { 461 result.AppendNull() 462 } 463 } 464 return nil 465 } 466 467 func (b *builtinCaseWhenStringSig) vectorized() bool { 468 return true 469 } 470 471 func (b *builtinCaseWhenTimeSig) fallbackEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 472 n := input.NumEvents() 473 result.ResizeTime(n, false) 474 x := result.Times() 475 for i := 0; i < n; i++ { 476 res, isNull, err := b.evalTime(input.GetEvent(i)) 477 if err != nil { 478 return err 479 } 480 result.SetNull(i, isNull) 481 if isNull { 482 continue 483 } 484 485 x[i] = res 486 487 } 488 return nil 489 } 490 491 func (b *builtinCaseWhenTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 492 n := input.NumEvents() 493 args, l := b.getArgs(), len(b.getArgs()) 494 whens := make([]*chunk.DeferredCauset, l/2) 495 whensSlice := make([][]int64, l/2) 496 thens := make([]*chunk.DeferredCauset, l/2) 497 var eLse *chunk.DeferredCauset 498 thensSlice := make([][]types.Time, l/2) 499 var eLseSlice []types.Time 500 sc := b.ctx.GetStochastikVars().StmtCtx 501 beforeWarns := sc.WarningCount() 502 503 for j := 0; j < l-1; j += 2 { 504 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 505 if err != nil { 506 return err 507 } 508 defer b.bufSlabPredictor.put(bufWhen) 509 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 510 afterWarns := sc.WarningCount() 511 if err != nil || afterWarns > beforeWarns { 512 if afterWarns > beforeWarns { 513 sc.TruncateWarnings(int(beforeWarns)) 514 } 515 return b.fallbackEvalTime(input, result) 516 } 517 whens[j/2] = bufWhen 518 whensSlice[j/2] = bufWhen.Int64s() 519 520 bufThen, err := b.bufSlabPredictor.get(types.ETDatetime, n) 521 if err != nil { 522 return err 523 } 524 defer b.bufSlabPredictor.put(bufThen) 525 err = args[j+1].VecEvalTime(b.ctx, input, bufThen) 526 afterWarns = sc.WarningCount() 527 if err != nil || afterWarns > beforeWarns { 528 if afterWarns > beforeWarns { 529 sc.TruncateWarnings(int(beforeWarns)) 530 } 531 return b.fallbackEvalTime(input, result) 532 } 533 thens[j/2] = bufThen 534 thensSlice[j/2] = bufThen.Times() 535 } 536 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 537 // else clause -> args[l-1] 538 // If case clause has else clause, l%2 == 1. 539 if l%2 == 1 { 540 bufElse, err := b.bufSlabPredictor.get(types.ETDatetime, n) 541 if err != nil { 542 return err 543 } 544 defer b.bufSlabPredictor.put(bufElse) 545 err = args[l-1].VecEvalTime(b.ctx, input, bufElse) 546 afterWarns := sc.WarningCount() 547 if err != nil || afterWarns > beforeWarns { 548 if afterWarns > beforeWarns { 549 sc.TruncateWarnings(int(beforeWarns)) 550 } 551 return b.fallbackEvalTime(input, result) 552 } 553 eLse = bufElse 554 eLseSlice = bufElse.Times() 555 } 556 result.ResizeTime(n, false) 557 resultSlice := result.Times() 558 ROW: 559 for i := 0; i < n; i++ { 560 for j := 0; j < l/2; j++ { 561 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 562 continue 563 } 564 resultSlice[i] = thensSlice[j][i] 565 result.SetNull(i, thens[j].IsNull(i)) 566 continue ROW 567 } 568 if eLse != nil { 569 resultSlice[i] = eLseSlice[i] 570 result.SetNull(i, eLse.IsNull(i)) 571 } else { 572 result.SetNull(i, true) 573 } 574 } 575 return nil 576 } 577 578 func (b *builtinCaseWhenTimeSig) vectorized() bool { 579 return true 580 } 581 582 func (b *builtinCaseWhenDurationSig) fallbackEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 583 n := input.NumEvents() 584 result.ResizeGoDuration(n, false) 585 x := result.GoDurations() 586 for i := 0; i < n; i++ { 587 res, isNull, err := b.evalDuration(input.GetEvent(i)) 588 if err != nil { 589 return err 590 } 591 result.SetNull(i, isNull) 592 if isNull { 593 continue 594 } 595 596 x[i] = res.Duration 597 598 } 599 return nil 600 } 601 602 func (b *builtinCaseWhenDurationSig) vecEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 603 n := input.NumEvents() 604 args, l := b.getArgs(), len(b.getArgs()) 605 whens := make([]*chunk.DeferredCauset, l/2) 606 whensSlice := make([][]int64, l/2) 607 thens := make([]*chunk.DeferredCauset, l/2) 608 var eLse *chunk.DeferredCauset 609 thensSlice := make([][]time.Duration, l/2) 610 var eLseSlice []time.Duration 611 sc := b.ctx.GetStochastikVars().StmtCtx 612 beforeWarns := sc.WarningCount() 613 614 for j := 0; j < l-1; j += 2 { 615 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 616 if err != nil { 617 return err 618 } 619 defer b.bufSlabPredictor.put(bufWhen) 620 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 621 afterWarns := sc.WarningCount() 622 if err != nil || afterWarns > beforeWarns { 623 if afterWarns > beforeWarns { 624 sc.TruncateWarnings(int(beforeWarns)) 625 } 626 return b.fallbackEvalDuration(input, result) 627 } 628 whens[j/2] = bufWhen 629 whensSlice[j/2] = bufWhen.Int64s() 630 631 bufThen, err := b.bufSlabPredictor.get(types.ETDuration, n) 632 if err != nil { 633 return err 634 } 635 defer b.bufSlabPredictor.put(bufThen) 636 err = args[j+1].VecEvalDuration(b.ctx, input, bufThen) 637 afterWarns = sc.WarningCount() 638 if err != nil || afterWarns > beforeWarns { 639 if afterWarns > beforeWarns { 640 sc.TruncateWarnings(int(beforeWarns)) 641 } 642 return b.fallbackEvalDuration(input, result) 643 } 644 thens[j/2] = bufThen 645 thensSlice[j/2] = bufThen.GoDurations() 646 } 647 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 648 // else clause -> args[l-1] 649 // If case clause has else clause, l%2 == 1. 650 if l%2 == 1 { 651 bufElse, err := b.bufSlabPredictor.get(types.ETDuration, n) 652 if err != nil { 653 return err 654 } 655 defer b.bufSlabPredictor.put(bufElse) 656 err = args[l-1].VecEvalDuration(b.ctx, input, bufElse) 657 afterWarns := sc.WarningCount() 658 if err != nil || afterWarns > beforeWarns { 659 if afterWarns > beforeWarns { 660 sc.TruncateWarnings(int(beforeWarns)) 661 } 662 return b.fallbackEvalDuration(input, result) 663 } 664 eLse = bufElse 665 eLseSlice = bufElse.GoDurations() 666 } 667 result.ResizeGoDuration(n, false) 668 resultSlice := result.GoDurations() 669 ROW: 670 for i := 0; i < n; i++ { 671 for j := 0; j < l/2; j++ { 672 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 673 continue 674 } 675 resultSlice[i] = thensSlice[j][i] 676 result.SetNull(i, thens[j].IsNull(i)) 677 continue ROW 678 } 679 if eLse != nil { 680 resultSlice[i] = eLseSlice[i] 681 result.SetNull(i, eLse.IsNull(i)) 682 } else { 683 result.SetNull(i, true) 684 } 685 } 686 return nil 687 } 688 689 func (b *builtinCaseWhenDurationSig) vectorized() bool { 690 return true 691 } 692 693 func (b *builtinCaseWhenJSONSig) fallbackEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 694 n := input.NumEvents() 695 result.ReserveJSON(n) 696 for i := 0; i < n; i++ { 697 res, isNull, err := b.evalJSON(input.GetEvent(i)) 698 if err != nil { 699 return err 700 } 701 if isNull { 702 result.AppendNull() 703 continue 704 } 705 result.AppendJSON(res) 706 } 707 return nil 708 } 709 710 func (b *builtinCaseWhenJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 711 n := input.NumEvents() 712 args, l := b.getArgs(), len(b.getArgs()) 713 whens := make([]*chunk.DeferredCauset, l/2) 714 whensSlice := make([][]int64, l/2) 715 thens := make([]*chunk.DeferredCauset, l/2) 716 var eLse *chunk.DeferredCauset 717 sc := b.ctx.GetStochastikVars().StmtCtx 718 beforeWarns := sc.WarningCount() 719 720 for j := 0; j < l-1; j += 2 { 721 bufWhen, err := b.bufSlabPredictor.get(types.ETInt, n) 722 if err != nil { 723 return err 724 } 725 defer b.bufSlabPredictor.put(bufWhen) 726 err = args[j].VecEvalInt(b.ctx, input, bufWhen) 727 afterWarns := sc.WarningCount() 728 if err != nil || afterWarns > beforeWarns { 729 if afterWarns > beforeWarns { 730 sc.TruncateWarnings(int(beforeWarns)) 731 } 732 return b.fallbackEvalJSON(input, result) 733 } 734 whens[j/2] = bufWhen 735 whensSlice[j/2] = bufWhen.Int64s() 736 737 bufThen, err := b.bufSlabPredictor.get(types.ETJson, n) 738 if err != nil { 739 return err 740 } 741 defer b.bufSlabPredictor.put(bufThen) 742 err = args[j+1].VecEvalJSON(b.ctx, input, bufThen) 743 afterWarns = sc.WarningCount() 744 if err != nil || afterWarns > beforeWarns { 745 if afterWarns > beforeWarns { 746 sc.TruncateWarnings(int(beforeWarns)) 747 } 748 return b.fallbackEvalJSON(input, result) 749 } 750 thens[j/2] = bufThen 751 } 752 // when clause(condition, result) -> args[i], args[i+1]; (i >= 0 && i+1 < l-1) 753 // else clause -> args[l-1] 754 // If case clause has else clause, l%2 == 1. 755 if l%2 == 1 { 756 bufElse, err := b.bufSlabPredictor.get(types.ETJson, n) 757 if err != nil { 758 return err 759 } 760 defer b.bufSlabPredictor.put(bufElse) 761 err = args[l-1].VecEvalJSON(b.ctx, input, bufElse) 762 afterWarns := sc.WarningCount() 763 if err != nil || afterWarns > beforeWarns { 764 if afterWarns > beforeWarns { 765 sc.TruncateWarnings(int(beforeWarns)) 766 } 767 return b.fallbackEvalJSON(input, result) 768 } 769 eLse = bufElse 770 } 771 result.ReserveJSON(n) 772 ROW: 773 for i := 0; i < n; i++ { 774 for j := 0; j < l/2; j++ { 775 if whens[j].IsNull(i) || whensSlice[j][i] == 0 { 776 continue 777 } 778 if thens[j].IsNull(i) { 779 result.AppendNull() 780 } else { 781 result.AppendJSON(thens[j].GetJSON(i)) 782 } 783 continue ROW 784 } 785 if eLse != nil { 786 if eLse.IsNull(i) { 787 result.AppendNull() 788 } else { 789 result.AppendJSON(eLse.GetJSON(i)) 790 } 791 } else { 792 result.AppendNull() 793 } 794 } 795 return nil 796 } 797 798 func (b *builtinCaseWhenJSONSig) vectorized() bool { 799 return true 800 } 801 802 func (b *builtinIfNullIntSig) fallbackEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 803 n := input.NumEvents() 804 x := result.Int64s() 805 for i := 0; i < n; i++ { 806 res, isNull, err := b.evalInt(input.GetEvent(i)) 807 if err != nil { 808 return err 809 } 810 result.SetNull(i, isNull) 811 if isNull { 812 continue 813 } 814 815 x[i] = res 816 817 } 818 return nil 819 } 820 821 func (b *builtinIfNullIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 822 n := input.NumEvents() 823 if err := b.args[0].VecEvalInt(b.ctx, input, result); err != nil { 824 return err 825 } 826 buf1, err := b.bufSlabPredictor.get(types.ETInt, n) 827 if err != nil { 828 return err 829 } 830 defer b.bufSlabPredictor.put(buf1) 831 sc := b.ctx.GetStochastikVars().StmtCtx 832 beforeWarns := sc.WarningCount() 833 err = b.args[1].VecEvalInt(b.ctx, input, buf1) 834 afterWarns := sc.WarningCount() 835 if err != nil || afterWarns > beforeWarns { 836 if afterWarns > beforeWarns { 837 sc.TruncateWarnings(int(beforeWarns)) 838 } 839 return b.fallbackEvalInt(input, result) 840 } 841 arg0 := result.Int64s() 842 arg1 := buf1.Int64s() 843 for i := 0; i < n; i++ { 844 if result.IsNull(i) && !buf1.IsNull(i) { 845 result.SetNull(i, false) 846 arg0[i] = arg1[i] 847 } 848 } 849 return nil 850 } 851 852 func (b *builtinIfNullIntSig) vectorized() bool { 853 return true 854 } 855 856 func (b *builtinIfNullRealSig) fallbackEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 857 n := input.NumEvents() 858 x := result.Float64s() 859 for i := 0; i < n; i++ { 860 res, isNull, err := b.evalReal(input.GetEvent(i)) 861 if err != nil { 862 return err 863 } 864 result.SetNull(i, isNull) 865 if isNull { 866 continue 867 } 868 869 x[i] = res 870 871 } 872 return nil 873 } 874 875 func (b *builtinIfNullRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 876 n := input.NumEvents() 877 if err := b.args[0].VecEvalReal(b.ctx, input, result); err != nil { 878 return err 879 } 880 buf1, err := b.bufSlabPredictor.get(types.ETReal, n) 881 if err != nil { 882 return err 883 } 884 defer b.bufSlabPredictor.put(buf1) 885 sc := b.ctx.GetStochastikVars().StmtCtx 886 beforeWarns := sc.WarningCount() 887 err = b.args[1].VecEvalReal(b.ctx, input, buf1) 888 afterWarns := sc.WarningCount() 889 if err != nil || afterWarns > beforeWarns { 890 if afterWarns > beforeWarns { 891 sc.TruncateWarnings(int(beforeWarns)) 892 } 893 return b.fallbackEvalReal(input, result) 894 } 895 arg0 := result.Float64s() 896 arg1 := buf1.Float64s() 897 for i := 0; i < n; i++ { 898 if result.IsNull(i) && !buf1.IsNull(i) { 899 result.SetNull(i, false) 900 arg0[i] = arg1[i] 901 } 902 } 903 return nil 904 } 905 906 func (b *builtinIfNullRealSig) vectorized() bool { 907 return true 908 } 909 910 func (b *builtinIfNullDecimalSig) fallbackEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 911 n := input.NumEvents() 912 x := result.Decimals() 913 for i := 0; i < n; i++ { 914 res, isNull, err := b.evalDecimal(input.GetEvent(i)) 915 if err != nil { 916 return err 917 } 918 result.SetNull(i, isNull) 919 if isNull { 920 continue 921 } 922 923 x[i] = *res 924 925 } 926 return nil 927 } 928 929 func (b *builtinIfNullDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 930 n := input.NumEvents() 931 if err := b.args[0].VecEvalDecimal(b.ctx, input, result); err != nil { 932 return err 933 } 934 buf1, err := b.bufSlabPredictor.get(types.ETDecimal, n) 935 if err != nil { 936 return err 937 } 938 defer b.bufSlabPredictor.put(buf1) 939 sc := b.ctx.GetStochastikVars().StmtCtx 940 beforeWarns := sc.WarningCount() 941 err = b.args[1].VecEvalDecimal(b.ctx, input, buf1) 942 afterWarns := sc.WarningCount() 943 if err != nil || afterWarns > beforeWarns { 944 if afterWarns > beforeWarns { 945 sc.TruncateWarnings(int(beforeWarns)) 946 } 947 return b.fallbackEvalDecimal(input, result) 948 } 949 arg0 := result.Decimals() 950 arg1 := buf1.Decimals() 951 for i := 0; i < n; i++ { 952 if result.IsNull(i) && !buf1.IsNull(i) { 953 result.SetNull(i, false) 954 arg0[i] = arg1[i] 955 } 956 } 957 return nil 958 } 959 960 func (b *builtinIfNullDecimalSig) vectorized() bool { 961 return true 962 } 963 964 func (b *builtinIfNullStringSig) fallbackEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 965 n := input.NumEvents() 966 result.ReserveString(n) 967 for i := 0; i < n; i++ { 968 res, isNull, err := b.evalString(input.GetEvent(i)) 969 if err != nil { 970 return err 971 } 972 if isNull { 973 result.AppendNull() 974 continue 975 } 976 result.AppendString(res) 977 } 978 return nil 979 } 980 981 func (b *builtinIfNullStringSig) vecEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 982 n := input.NumEvents() 983 buf0, err := b.bufSlabPredictor.get(types.ETString, n) 984 if err != nil { 985 return err 986 } 987 defer b.bufSlabPredictor.put(buf0) 988 if err := b.args[0].VecEvalString(b.ctx, input, buf0); err != nil { 989 return err 990 } 991 buf1, err := b.bufSlabPredictor.get(types.ETString, n) 992 if err != nil { 993 return err 994 } 995 defer b.bufSlabPredictor.put(buf1) 996 sc := b.ctx.GetStochastikVars().StmtCtx 997 beforeWarns := sc.WarningCount() 998 err = b.args[1].VecEvalString(b.ctx, input, buf1) 999 afterWarns := sc.WarningCount() 1000 if err != nil || afterWarns > beforeWarns { 1001 if afterWarns > beforeWarns { 1002 sc.TruncateWarnings(int(beforeWarns)) 1003 } 1004 return b.fallbackEvalString(input, result) 1005 } 1006 1007 result.ReserveString(n) 1008 for i := 0; i < n; i++ { 1009 if !buf0.IsNull(i) { 1010 result.AppendString(buf0.GetString(i)) 1011 } else if !buf1.IsNull(i) { 1012 result.AppendString(buf1.GetString(i)) 1013 } else { 1014 result.AppendNull() 1015 } 1016 } 1017 return nil 1018 } 1019 1020 func (b *builtinIfNullStringSig) vectorized() bool { 1021 return true 1022 } 1023 1024 func (b *builtinIfNullTimeSig) fallbackEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1025 n := input.NumEvents() 1026 x := result.Times() 1027 for i := 0; i < n; i++ { 1028 res, isNull, err := b.evalTime(input.GetEvent(i)) 1029 if err != nil { 1030 return err 1031 } 1032 result.SetNull(i, isNull) 1033 if isNull { 1034 continue 1035 } 1036 1037 x[i] = res 1038 1039 } 1040 return nil 1041 } 1042 1043 func (b *builtinIfNullTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1044 n := input.NumEvents() 1045 if err := b.args[0].VecEvalTime(b.ctx, input, result); err != nil { 1046 return err 1047 } 1048 buf1, err := b.bufSlabPredictor.get(types.ETDatetime, n) 1049 if err != nil { 1050 return err 1051 } 1052 defer b.bufSlabPredictor.put(buf1) 1053 sc := b.ctx.GetStochastikVars().StmtCtx 1054 beforeWarns := sc.WarningCount() 1055 err = b.args[1].VecEvalTime(b.ctx, input, buf1) 1056 afterWarns := sc.WarningCount() 1057 if err != nil || afterWarns > beforeWarns { 1058 if afterWarns > beforeWarns { 1059 sc.TruncateWarnings(int(beforeWarns)) 1060 } 1061 return b.fallbackEvalTime(input, result) 1062 } 1063 arg0 := result.Times() 1064 arg1 := buf1.Times() 1065 for i := 0; i < n; i++ { 1066 if result.IsNull(i) && !buf1.IsNull(i) { 1067 result.SetNull(i, false) 1068 arg0[i] = arg1[i] 1069 } 1070 } 1071 return nil 1072 } 1073 1074 func (b *builtinIfNullTimeSig) vectorized() bool { 1075 return true 1076 } 1077 1078 func (b *builtinIfNullDurationSig) fallbackEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1079 n := input.NumEvents() 1080 x := result.GoDurations() 1081 for i := 0; i < n; i++ { 1082 res, isNull, err := b.evalDuration(input.GetEvent(i)) 1083 if err != nil { 1084 return err 1085 } 1086 result.SetNull(i, isNull) 1087 if isNull { 1088 continue 1089 } 1090 1091 x[i] = res.Duration 1092 1093 } 1094 return nil 1095 } 1096 1097 func (b *builtinIfNullDurationSig) vecEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1098 n := input.NumEvents() 1099 if err := b.args[0].VecEvalDuration(b.ctx, input, result); err != nil { 1100 return err 1101 } 1102 buf1, err := b.bufSlabPredictor.get(types.ETDuration, n) 1103 if err != nil { 1104 return err 1105 } 1106 defer b.bufSlabPredictor.put(buf1) 1107 sc := b.ctx.GetStochastikVars().StmtCtx 1108 beforeWarns := sc.WarningCount() 1109 err = b.args[1].VecEvalDuration(b.ctx, input, buf1) 1110 afterWarns := sc.WarningCount() 1111 if err != nil || afterWarns > beforeWarns { 1112 if afterWarns > beforeWarns { 1113 sc.TruncateWarnings(int(beforeWarns)) 1114 } 1115 return b.fallbackEvalDuration(input, result) 1116 } 1117 arg0 := result.GoDurations() 1118 arg1 := buf1.GoDurations() 1119 for i := 0; i < n; i++ { 1120 if result.IsNull(i) && !buf1.IsNull(i) { 1121 result.SetNull(i, false) 1122 arg0[i] = arg1[i] 1123 } 1124 } 1125 return nil 1126 } 1127 1128 func (b *builtinIfNullDurationSig) vectorized() bool { 1129 return true 1130 } 1131 1132 func (b *builtinIfNullJSONSig) fallbackEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1133 n := input.NumEvents() 1134 result.ReserveJSON(n) 1135 for i := 0; i < n; i++ { 1136 res, isNull, err := b.evalJSON(input.GetEvent(i)) 1137 if err != nil { 1138 return err 1139 } 1140 if isNull { 1141 result.AppendNull() 1142 continue 1143 } 1144 result.AppendJSON(res) 1145 } 1146 return nil 1147 } 1148 1149 func (b *builtinIfNullJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1150 n := input.NumEvents() 1151 buf0, err := b.bufSlabPredictor.get(types.ETJson, n) 1152 if err != nil { 1153 return err 1154 } 1155 defer b.bufSlabPredictor.put(buf0) 1156 if err := b.args[0].VecEvalJSON(b.ctx, input, buf0); err != nil { 1157 return err 1158 } 1159 buf1, err := b.bufSlabPredictor.get(types.ETJson, n) 1160 if err != nil { 1161 return err 1162 } 1163 defer b.bufSlabPredictor.put(buf1) 1164 sc := b.ctx.GetStochastikVars().StmtCtx 1165 beforeWarns := sc.WarningCount() 1166 err = b.args[1].VecEvalJSON(b.ctx, input, buf1) 1167 afterWarns := sc.WarningCount() 1168 if err != nil || afterWarns > beforeWarns { 1169 if afterWarns > beforeWarns { 1170 sc.TruncateWarnings(int(beforeWarns)) 1171 } 1172 return b.fallbackEvalJSON(input, result) 1173 } 1174 1175 result.ReserveJSON(n) 1176 for i := 0; i < n; i++ { 1177 if !buf0.IsNull(i) { 1178 result.AppendJSON(buf0.GetJSON(i)) 1179 } else if !buf1.IsNull(i) { 1180 result.AppendJSON(buf1.GetJSON(i)) 1181 } else { 1182 result.AppendNull() 1183 } 1184 } 1185 return nil 1186 } 1187 1188 func (b *builtinIfNullJSONSig) vectorized() bool { 1189 return true 1190 } 1191 1192 func (b *builtinIfIntSig) fallbackEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1193 n := input.NumEvents() 1194 x := result.Int64s() 1195 for i := 0; i < n; i++ { 1196 res, isNull, err := b.evalInt(input.GetEvent(i)) 1197 if err != nil { 1198 return err 1199 } 1200 result.SetNull(i, isNull) 1201 if isNull { 1202 continue 1203 } 1204 1205 x[i] = res 1206 1207 } 1208 return nil 1209 } 1210 1211 func (b *builtinIfIntSig) vecEvalInt(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1212 n := input.NumEvents() 1213 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1214 if err != nil { 1215 return err 1216 } 1217 defer b.bufSlabPredictor.put(buf0) 1218 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1219 return err 1220 } 1221 sc := b.ctx.GetStochastikVars().StmtCtx 1222 beforeWarns := sc.WarningCount() 1223 err = b.args[1].VecEvalInt(b.ctx, input, result) 1224 afterWarns := sc.WarningCount() 1225 if err != nil || afterWarns > beforeWarns { 1226 if afterWarns > beforeWarns { 1227 sc.TruncateWarnings(int(beforeWarns)) 1228 } 1229 return b.fallbackEvalInt(input, result) 1230 } 1231 1232 buf2, err := b.bufSlabPredictor.get(types.ETInt, n) 1233 if err != nil { 1234 return err 1235 } 1236 defer b.bufSlabPredictor.put(buf2) 1237 err = b.args[2].VecEvalInt(b.ctx, input, buf2) 1238 afterWarns = sc.WarningCount() 1239 if err != nil || afterWarns > beforeWarns { 1240 if afterWarns > beforeWarns { 1241 sc.TruncateWarnings(int(beforeWarns)) 1242 } 1243 return b.fallbackEvalInt(input, result) 1244 } 1245 1246 arg0 := buf0.Int64s() 1247 arg2 := buf2.Int64s() 1248 rs := result.Int64s() 1249 for i := 0; i < n; i++ { 1250 arg := arg0[i] 1251 isNull0 := buf0.IsNull(i) 1252 switch { 1253 case isNull0 || arg == 0: 1254 if buf2.IsNull(i) { 1255 result.SetNull(i, true) 1256 } else { 1257 result.SetNull(i, false) 1258 rs[i] = arg2[i] 1259 } 1260 case arg != 0: 1261 } 1262 } 1263 return nil 1264 } 1265 1266 func (b *builtinIfIntSig) vectorized() bool { 1267 return true 1268 } 1269 1270 func (b *builtinIfRealSig) fallbackEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1271 n := input.NumEvents() 1272 x := result.Float64s() 1273 for i := 0; i < n; i++ { 1274 res, isNull, err := b.evalReal(input.GetEvent(i)) 1275 if err != nil { 1276 return err 1277 } 1278 result.SetNull(i, isNull) 1279 if isNull { 1280 continue 1281 } 1282 1283 x[i] = res 1284 1285 } 1286 return nil 1287 } 1288 1289 func (b *builtinIfRealSig) vecEvalReal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1290 n := input.NumEvents() 1291 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1292 if err != nil { 1293 return err 1294 } 1295 defer b.bufSlabPredictor.put(buf0) 1296 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1297 return err 1298 } 1299 sc := b.ctx.GetStochastikVars().StmtCtx 1300 beforeWarns := sc.WarningCount() 1301 err = b.args[1].VecEvalReal(b.ctx, input, result) 1302 afterWarns := sc.WarningCount() 1303 if err != nil || afterWarns > beforeWarns { 1304 if afterWarns > beforeWarns { 1305 sc.TruncateWarnings(int(beforeWarns)) 1306 } 1307 return b.fallbackEvalReal(input, result) 1308 } 1309 1310 buf2, err := b.bufSlabPredictor.get(types.ETReal, n) 1311 if err != nil { 1312 return err 1313 } 1314 defer b.bufSlabPredictor.put(buf2) 1315 err = b.args[2].VecEvalReal(b.ctx, input, buf2) 1316 afterWarns = sc.WarningCount() 1317 if err != nil || afterWarns > beforeWarns { 1318 if afterWarns > beforeWarns { 1319 sc.TruncateWarnings(int(beforeWarns)) 1320 } 1321 return b.fallbackEvalReal(input, result) 1322 } 1323 1324 arg0 := buf0.Int64s() 1325 arg2 := buf2.Float64s() 1326 rs := result.Float64s() 1327 for i := 0; i < n; i++ { 1328 arg := arg0[i] 1329 isNull0 := buf0.IsNull(i) 1330 switch { 1331 case isNull0 || arg == 0: 1332 if buf2.IsNull(i) { 1333 result.SetNull(i, true) 1334 } else { 1335 result.SetNull(i, false) 1336 rs[i] = arg2[i] 1337 } 1338 case arg != 0: 1339 } 1340 } 1341 return nil 1342 } 1343 1344 func (b *builtinIfRealSig) vectorized() bool { 1345 return true 1346 } 1347 1348 func (b *builtinIfDecimalSig) fallbackEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1349 n := input.NumEvents() 1350 x := result.Decimals() 1351 for i := 0; i < n; i++ { 1352 res, isNull, err := b.evalDecimal(input.GetEvent(i)) 1353 if err != nil { 1354 return err 1355 } 1356 result.SetNull(i, isNull) 1357 if isNull { 1358 continue 1359 } 1360 1361 x[i] = *res 1362 1363 } 1364 return nil 1365 } 1366 1367 func (b *builtinIfDecimalSig) vecEvalDecimal(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1368 n := input.NumEvents() 1369 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1370 if err != nil { 1371 return err 1372 } 1373 defer b.bufSlabPredictor.put(buf0) 1374 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1375 return err 1376 } 1377 sc := b.ctx.GetStochastikVars().StmtCtx 1378 beforeWarns := sc.WarningCount() 1379 err = b.args[1].VecEvalDecimal(b.ctx, input, result) 1380 afterWarns := sc.WarningCount() 1381 if err != nil || afterWarns > beforeWarns { 1382 if afterWarns > beforeWarns { 1383 sc.TruncateWarnings(int(beforeWarns)) 1384 } 1385 return b.fallbackEvalDecimal(input, result) 1386 } 1387 1388 buf2, err := b.bufSlabPredictor.get(types.ETDecimal, n) 1389 if err != nil { 1390 return err 1391 } 1392 defer b.bufSlabPredictor.put(buf2) 1393 err = b.args[2].VecEvalDecimal(b.ctx, input, buf2) 1394 afterWarns = sc.WarningCount() 1395 if err != nil || afterWarns > beforeWarns { 1396 if afterWarns > beforeWarns { 1397 sc.TruncateWarnings(int(beforeWarns)) 1398 } 1399 return b.fallbackEvalDecimal(input, result) 1400 } 1401 1402 arg0 := buf0.Int64s() 1403 arg2 := buf2.Decimals() 1404 rs := result.Decimals() 1405 for i := 0; i < n; i++ { 1406 arg := arg0[i] 1407 isNull0 := buf0.IsNull(i) 1408 switch { 1409 case isNull0 || arg == 0: 1410 if buf2.IsNull(i) { 1411 result.SetNull(i, true) 1412 } else { 1413 result.SetNull(i, false) 1414 rs[i] = arg2[i] 1415 } 1416 case arg != 0: 1417 } 1418 } 1419 return nil 1420 } 1421 1422 func (b *builtinIfDecimalSig) vectorized() bool { 1423 return true 1424 } 1425 1426 func (b *builtinIfStringSig) fallbackEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1427 n := input.NumEvents() 1428 result.ReserveString(n) 1429 for i := 0; i < n; i++ { 1430 res, isNull, err := b.evalString(input.GetEvent(i)) 1431 if err != nil { 1432 return err 1433 } 1434 if isNull { 1435 result.AppendNull() 1436 continue 1437 } 1438 result.AppendString(res) 1439 } 1440 return nil 1441 } 1442 1443 func (b *builtinIfStringSig) vecEvalString(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1444 n := input.NumEvents() 1445 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1446 if err != nil { 1447 return err 1448 } 1449 defer b.bufSlabPredictor.put(buf0) 1450 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1451 return err 1452 } 1453 sc := b.ctx.GetStochastikVars().StmtCtx 1454 beforeWarns := sc.WarningCount() 1455 buf1, err := b.bufSlabPredictor.get(types.ETString, n) 1456 if err != nil { 1457 return err 1458 } 1459 defer b.bufSlabPredictor.put(buf1) 1460 err = b.args[1].VecEvalString(b.ctx, input, buf1) 1461 afterWarns := sc.WarningCount() 1462 if err != nil || afterWarns > beforeWarns { 1463 if afterWarns > beforeWarns { 1464 sc.TruncateWarnings(int(beforeWarns)) 1465 } 1466 return b.fallbackEvalString(input, result) 1467 } 1468 1469 buf2, err := b.bufSlabPredictor.get(types.ETString, n) 1470 if err != nil { 1471 return err 1472 } 1473 defer b.bufSlabPredictor.put(buf2) 1474 err = b.args[2].VecEvalString(b.ctx, input, buf2) 1475 afterWarns = sc.WarningCount() 1476 if err != nil || afterWarns > beforeWarns { 1477 if afterWarns > beforeWarns { 1478 sc.TruncateWarnings(int(beforeWarns)) 1479 } 1480 return b.fallbackEvalString(input, result) 1481 } 1482 1483 result.ReserveString(n) 1484 arg0 := buf0.Int64s() 1485 for i := 0; i < n; i++ { 1486 arg := arg0[i] 1487 isNull0 := buf0.IsNull(i) 1488 switch { 1489 case isNull0 || arg == 0: 1490 if buf2.IsNull(i) { 1491 result.AppendNull() 1492 } else { 1493 result.AppendString(buf2.GetString(i)) 1494 } 1495 case arg != 0: 1496 if buf1.IsNull(i) { 1497 result.AppendNull() 1498 } else { 1499 result.AppendString(buf1.GetString(i)) 1500 } 1501 } 1502 } 1503 return nil 1504 } 1505 1506 func (b *builtinIfStringSig) vectorized() bool { 1507 return true 1508 } 1509 1510 func (b *builtinIfTimeSig) fallbackEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1511 n := input.NumEvents() 1512 x := result.Times() 1513 for i := 0; i < n; i++ { 1514 res, isNull, err := b.evalTime(input.GetEvent(i)) 1515 if err != nil { 1516 return err 1517 } 1518 result.SetNull(i, isNull) 1519 if isNull { 1520 continue 1521 } 1522 1523 x[i] = res 1524 1525 } 1526 return nil 1527 } 1528 1529 func (b *builtinIfTimeSig) vecEvalTime(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1530 n := input.NumEvents() 1531 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1532 if err != nil { 1533 return err 1534 } 1535 defer b.bufSlabPredictor.put(buf0) 1536 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1537 return err 1538 } 1539 sc := b.ctx.GetStochastikVars().StmtCtx 1540 beforeWarns := sc.WarningCount() 1541 err = b.args[1].VecEvalTime(b.ctx, input, result) 1542 afterWarns := sc.WarningCount() 1543 if err != nil || afterWarns > beforeWarns { 1544 if afterWarns > beforeWarns { 1545 sc.TruncateWarnings(int(beforeWarns)) 1546 } 1547 return b.fallbackEvalTime(input, result) 1548 } 1549 1550 buf2, err := b.bufSlabPredictor.get(types.ETDatetime, n) 1551 if err != nil { 1552 return err 1553 } 1554 defer b.bufSlabPredictor.put(buf2) 1555 err = b.args[2].VecEvalTime(b.ctx, input, buf2) 1556 afterWarns = sc.WarningCount() 1557 if err != nil || afterWarns > beforeWarns { 1558 if afterWarns > beforeWarns { 1559 sc.TruncateWarnings(int(beforeWarns)) 1560 } 1561 return b.fallbackEvalTime(input, result) 1562 } 1563 1564 arg0 := buf0.Int64s() 1565 arg2 := buf2.Times() 1566 rs := result.Times() 1567 for i := 0; i < n; i++ { 1568 arg := arg0[i] 1569 isNull0 := buf0.IsNull(i) 1570 switch { 1571 case isNull0 || arg == 0: 1572 if buf2.IsNull(i) { 1573 result.SetNull(i, true) 1574 } else { 1575 result.SetNull(i, false) 1576 rs[i] = arg2[i] 1577 } 1578 case arg != 0: 1579 } 1580 } 1581 return nil 1582 } 1583 1584 func (b *builtinIfTimeSig) vectorized() bool { 1585 return true 1586 } 1587 1588 func (b *builtinIfDurationSig) fallbackEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1589 n := input.NumEvents() 1590 x := result.GoDurations() 1591 for i := 0; i < n; i++ { 1592 res, isNull, err := b.evalDuration(input.GetEvent(i)) 1593 if err != nil { 1594 return err 1595 } 1596 result.SetNull(i, isNull) 1597 if isNull { 1598 continue 1599 } 1600 1601 x[i] = res.Duration 1602 1603 } 1604 return nil 1605 } 1606 1607 func (b *builtinIfDurationSig) vecEvalDuration(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1608 n := input.NumEvents() 1609 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1610 if err != nil { 1611 return err 1612 } 1613 defer b.bufSlabPredictor.put(buf0) 1614 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1615 return err 1616 } 1617 sc := b.ctx.GetStochastikVars().StmtCtx 1618 beforeWarns := sc.WarningCount() 1619 err = b.args[1].VecEvalDuration(b.ctx, input, result) 1620 afterWarns := sc.WarningCount() 1621 if err != nil || afterWarns > beforeWarns { 1622 if afterWarns > beforeWarns { 1623 sc.TruncateWarnings(int(beforeWarns)) 1624 } 1625 return b.fallbackEvalDuration(input, result) 1626 } 1627 1628 buf2, err := b.bufSlabPredictor.get(types.ETDuration, n) 1629 if err != nil { 1630 return err 1631 } 1632 defer b.bufSlabPredictor.put(buf2) 1633 err = b.args[2].VecEvalDuration(b.ctx, input, buf2) 1634 afterWarns = sc.WarningCount() 1635 if err != nil || afterWarns > beforeWarns { 1636 if afterWarns > beforeWarns { 1637 sc.TruncateWarnings(int(beforeWarns)) 1638 } 1639 return b.fallbackEvalDuration(input, result) 1640 } 1641 1642 arg0 := buf0.Int64s() 1643 arg2 := buf2.GoDurations() 1644 rs := result.GoDurations() 1645 for i := 0; i < n; i++ { 1646 arg := arg0[i] 1647 isNull0 := buf0.IsNull(i) 1648 switch { 1649 case isNull0 || arg == 0: 1650 if buf2.IsNull(i) { 1651 result.SetNull(i, true) 1652 } else { 1653 result.SetNull(i, false) 1654 rs[i] = arg2[i] 1655 } 1656 case arg != 0: 1657 } 1658 } 1659 return nil 1660 } 1661 1662 func (b *builtinIfDurationSig) vectorized() bool { 1663 return true 1664 } 1665 1666 func (b *builtinIfJSONSig) fallbackEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1667 n := input.NumEvents() 1668 result.ReserveJSON(n) 1669 for i := 0; i < n; i++ { 1670 res, isNull, err := b.evalJSON(input.GetEvent(i)) 1671 if err != nil { 1672 return err 1673 } 1674 if isNull { 1675 result.AppendNull() 1676 continue 1677 } 1678 result.AppendJSON(res) 1679 } 1680 return nil 1681 } 1682 1683 func (b *builtinIfJSONSig) vecEvalJSON(input *chunk.Chunk, result *chunk.DeferredCauset) error { 1684 n := input.NumEvents() 1685 buf0, err := b.bufSlabPredictor.get(types.ETInt, n) 1686 if err != nil { 1687 return err 1688 } 1689 defer b.bufSlabPredictor.put(buf0) 1690 if err := b.args[0].VecEvalInt(b.ctx, input, buf0); err != nil { 1691 return err 1692 } 1693 sc := b.ctx.GetStochastikVars().StmtCtx 1694 beforeWarns := sc.WarningCount() 1695 buf1, err := b.bufSlabPredictor.get(types.ETJson, n) 1696 if err != nil { 1697 return err 1698 } 1699 defer b.bufSlabPredictor.put(buf1) 1700 err = b.args[1].VecEvalJSON(b.ctx, input, buf1) 1701 afterWarns := sc.WarningCount() 1702 if err != nil || afterWarns > beforeWarns { 1703 if afterWarns > beforeWarns { 1704 sc.TruncateWarnings(int(beforeWarns)) 1705 } 1706 return b.fallbackEvalJSON(input, result) 1707 } 1708 1709 buf2, err := b.bufSlabPredictor.get(types.ETJson, n) 1710 if err != nil { 1711 return err 1712 } 1713 defer b.bufSlabPredictor.put(buf2) 1714 err = b.args[2].VecEvalJSON(b.ctx, input, buf2) 1715 afterWarns = sc.WarningCount() 1716 if err != nil || afterWarns > beforeWarns { 1717 if afterWarns > beforeWarns { 1718 sc.TruncateWarnings(int(beforeWarns)) 1719 } 1720 return b.fallbackEvalJSON(input, result) 1721 } 1722 1723 result.ReserveJSON(n) 1724 arg0 := buf0.Int64s() 1725 for i := 0; i < n; i++ { 1726 arg := arg0[i] 1727 isNull0 := buf0.IsNull(i) 1728 switch { 1729 case isNull0 || arg == 0: 1730 if buf2.IsNull(i) { 1731 result.AppendNull() 1732 } else { 1733 result.AppendJSON(buf2.GetJSON(i)) 1734 } 1735 case arg != 0: 1736 if buf1.IsNull(i) { 1737 result.AppendNull() 1738 } else { 1739 result.AppendJSON(buf1.GetJSON(i)) 1740 } 1741 } 1742 } 1743 return nil 1744 } 1745 1746 func (b *builtinIfJSONSig) vectorized() bool { 1747 return true 1748 }