| 470 | } |
| 471 | |
| 472 | void CastExpr::apply( |
| 473 | const SelectivityVector& rows, |
| 474 | const VectorPtr& input, |
| 475 | exec::EvalCtx& context, |
| 476 | const TypePtr& fromType, |
| 477 | const TypePtr& toType, |
| 478 | VectorPtr& result) { |
| 479 | LocalSelectivityVector remainingRows(context, rows); |
| 480 | |
| 481 | context.deselectErrors(*remainingRows); |
| 482 | |
| 483 | LocalDecodedVector decoded(context, *input, *remainingRows); |
| 484 | auto* rawNulls = decoded->nulls(remainingRows.get()); |
| 485 | |
| 486 | if (rawNulls) { |
| 487 | remainingRows->deselectNulls( |
| 488 | rawNulls, remainingRows->begin(), remainingRows->end()); |
| 489 | } |
| 490 | |
| 491 | VectorPtr localResult; |
| 492 | if (!remainingRows->hasSelections()) { |
| 493 | localResult = |
| 494 | BaseVector::createNullConstant(toType, rows.end(), context.pool()); |
| 495 | } else if (decoded->isIdentityMapping()) { |
| 496 | applyPeeled( |
| 497 | *remainingRows, |
| 498 | *decoded->base(), |
| 499 | context, |
| 500 | fromType, |
| 501 | toType, |
| 502 | localResult); |
| 503 | } else { |
| 504 | withContextSaver([&](ContextSaver& saver) { |
| 505 | LocalSelectivityVector newRowsHolder(*context.execCtx()); |
| 506 | |
| 507 | LocalDecodedVector localDecoded(context); |
| 508 | std::vector<VectorPtr> peeledVectors; |
| 509 | auto peeledEncoding = PeeledEncoding::peel( |
| 510 | {input}, *remainingRows, localDecoded, true, peeledVectors); |
| 511 | BOLT_CHECK_EQ(peeledVectors.size(), 1); |
| 512 | if (peeledVectors[0]->isLazy()) { |
| 513 | peeledVectors[0] = |
| 514 | peeledVectors[0]->as<LazyVector>()->loadedVectorShared(); |
| 515 | } |
| 516 | auto newRows = |
| 517 | peeledEncoding->translateToInnerRows(*remainingRows, newRowsHolder); |
| 518 | double ratio = |
| 519 | static_cast<double>(newRows->countSelected()) / newRows->size(); |
| 520 | if (ratio <= 0.01 && fromType->isPrimitiveType()) { |
| 521 | auto newInputVec = |
| 522 | BaseVector::create(fromType, remainingRows->end(), context.pool()); |
| 523 | newInputVec->copy(input.get(), *remainingRows, nullptr, false); |
| 524 | applyPeeled( |
| 525 | *remainingRows, |
| 526 | *newInputVec, |
| 527 | context, |
| 528 | fromType, |
| 529 | toType, |
no test coverage detected