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

Method peelEncodings

bolt/expression/Expr.cpp:988–1062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

986 // its a shared subexpression.
987 const auto& rowsToPeel =
988 context.isFinalSelection() ? rows : *context.finalSelection();
989 auto numFields = context.row()->childrenSize();
990 std::vector<VectorPtr> vectorsToPeel;
991 vectorsToPeel.reserve(distinctFields_.size());
992 for (auto* field : distinctFields_) {
993 auto fieldIndex = field->index(context);
994 assert(fieldIndex >= 0 && fieldIndex < numFields);
995 auto fieldVector = context.getField(fieldIndex);
996 if (fieldVector->isConstantEncoding()) {
997 // Make sure constant encoded fields are loaded
998 fieldVector = context.ensureFieldLoaded(fieldIndex, rowsToPeel);
999 }
1000 vectorsToPeel.push_back(fieldVector);
1001 }
1002
1003 // Attempt peeling.
1004 BOLT_CHECK(!vectorsToPeel.empty());
1005 std::vector<VectorPtr> peeledVectors;
1006 auto peeledEncoding = PeeledEncoding::peel(
1007 vectorsToPeel, rowsToPeel, localDecoded, propagatesNulls_, peeledVectors);
1008
1009 if (!peeledEncoding) {
1010 return Expr::PeelEncodingsResult::empty();
1011 }
1012
1013 // Translate the relevant rows.
1014 SelectivityVector* newFinalSelection = nullptr;
1015 if (!context.isFinalSelection()) {
1016 newFinalSelection = peeledEncoding->translateToInnerRows(
1017 *context.finalSelection(), finalRowsHolder);
1018 }
1019 auto newRows = peeledEncoding->translateToInnerRows(rows, newRowsHolder);
1020
1021 // Save context and set the peel, peeled fields and final selection (if
1022 // applicable).
1023 context.saveAndReset(saver, rows);
1024 context.setPeeledEncoding(peeledEncoding);
1025 if (newFinalSelection) {
1026 *context.mutableFinalSelection() = newFinalSelection;
1027 }
1028 DCHECK_EQ(peeledVectors.size(), distinctFields_.size());
1029 for (int i = 0; i < peeledVectors.size(); ++i) {
1030 auto fieldIndex = distinctFields_[i]->index(context);
1031 context.setPeeled(fieldIndex, peeledVectors[i]);
1032 }
1033
1034 // If the expression depends on one dictionary, results are cacheable.
1035 bool mayCache = false;
1036 if (context.cacheEnabled()) {
1037 mayCache = distinctFields_.size() == 1 &&
1038 VectorEncoding::isDictionary(context.wrapEncoding()) &&
1039 !peeledVectors[0]->memoDisabled();
1040 }
1041
1042 BOLT_TEST_ADJUST(
1043 "bytedance::bolt::exec::Expr::peelEncodings::mayCache", &mayCache);
1044 return {newRows, finalRowsHolder.get(), mayCache};
1045}

Callers

nothing calls this directly

Calls 15

isDictionaryFunction · 0.85
isFinalSelectionMethod · 0.80
ensureFieldLoadedMethod · 0.80
translateToInnerRowsMethod · 0.80
saveAndResetMethod · 0.80
setPeeledMethod · 0.80
wrapEncodingMethod · 0.45
childrenSizeMethod · 0.45
rowMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
indexMethod · 0.45

Tested by

no test coverage detected