MCPcopy Create free account
hub / github.com/bytedance/bolt / applyTyped

Method applyTyped

bolt/functions/prestosql/InPredicate.cpp:580–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

578
579 template <typename T, typename F>
580 void applyTyped(
581 const SelectivityVector& rows,
582 const VectorPtr& arg,
583 exec::EvalCtx& context,
584 VectorPtr& result,
585 F&& testFunction) const {
586 BOLT_CHECK(filter_, "IN predicate supports only constant IN list");
587
588 // Indicates whether result can be true or null only, e.g. no false results.
589 const bool passOrNull = filter_->testNull();
590
591 if (arg->isConstantEncoding()) {
592 auto simpleArg = arg->asUnchecked<SimpleVector<T>>();
593 VectorPtr localResult;
594 if (simpleArg->isNullAt(rows.begin())) {
595 localResult = createBoolConstantNull(rows.end(), context);
596 } else {
597 bool pass = testFunction(simpleArg->valueAt(rows.begin()));
598 if (!pass && passOrNull) {
599 localResult = createBoolConstantNull(rows.end(), context);
600 } else {
601 localResult = createBoolConstant(pass, rows.end(), context);
602 }
603 }
604
605 context.moveOrCopyResult(localResult, rows, result);
606 return;
607 }
608
609 BOLT_CHECK_EQ(arg->encoding(), VectorEncoding::Simple::FLAT);
610 auto flatArg = arg->asUnchecked<FlatVector<T>>();
611
612 context.ensureWritable(rows, BOOLEAN(), result);
613 result->clearNulls(rows);
614 auto* boolResult = result->asUnchecked<FlatVector<bool>>();
615
616 auto* rawResults = boolResult->mutableRawValues<uint64_t>();
617
618 if (flatArg->mayHaveNulls() || passOrNull) {
619 rows.applyToSelected([&](auto row) {
620 if (flatArg->isNullAt(row)) {
621 boolResult->setNull(row, true);
622 } else {
623 bool pass = testFunction(flatArg->valueAtFast(row));
624 if (!pass && passOrNull) {
625 boolResult->setNull(row, true);
626 } else {
627 bits::setBit(rawResults, row, pass);
628 }
629 }
630 });
631 } else {
632 rows.applyToSelected([&](auto row) {
633 bool pass = testFunction(flatArg->valueAtFast(row));
634 bits::setBit(rawResults, row, pass);
635 });
636 }
637 }

Callers

nothing calls this directly

Calls 13

applyToSelectedMethod · 0.80
setBitFunction · 0.50
testNullMethod · 0.45
isNullAtMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
valueAtMethod · 0.45
encodingMethod · 0.45
ensureWritableMethod · 0.45
clearNullsMethod · 0.45
mayHaveNullsMethod · 0.45
setNullMethod · 0.45

Tested by

no test coverage detected