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

Function addConstant

bolt/vector/BaseVector.cpp:202–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200
201template <TypeKind kind>
202static VectorPtr addConstant(
203 vector_size_t size,
204 vector_size_t index,
205 VectorPtr vector,
206 bool copyBase) {
207 using T = typename KindToFlatVector<kind>::WrapperType;
208
209 auto pool = vector->pool();
210
211 if (vector->isNullAt(index)) {
212 if constexpr (std::is_same_v<T, ComplexType>) {
213 auto singleNull = BaseVector::create(vector->type(), 1, pool);
214 singleNull->setNull(0, true);
215 return std::make_shared<ConstantVector<T>>(
216 pool, size, 0, singleNull, SimpleVectorStats<T>{});
217 } else {
218 return std::make_shared<ConstantVector<T>>(
219 pool, size, true, vector->type(), T());
220 }
221 }
222
223 for (;;) {
224 if (vector->isConstantEncoding()) {
225 auto constVector = vector->as<ConstantVector<T>>();
226 if constexpr (!std::is_same_v<T, ComplexType>) {
227 if (!vector->valueVector()) {
228 T value = constVector->valueAt(0);
229 return std::make_shared<ConstantVector<T>>(
230 pool, size, false, vector->type(), std::move(value));
231 }
232 }
233
234 index = constVector->index();
235 vector = vector->valueVector();
236 } else if (vector->encoding() == VectorEncoding::Simple::DICTIONARY) {
237 const BufferPtr& indices = vector->as<DictionaryVector<T>>()->indices();
238 index = indices->as<vector_size_t>()[index];
239 vector = vector->valueVector();
240 } else {
241 break;
242 }
243 }
244
245 if (copyBase) {
246 VectorPtr copy = BaseVector::create(vector->type(), 1, pool);
247 copy->copy(vector.get(), 0, index, 1);
248 return std::make_shared<ConstantVector<T>>(
249 pool, size, 0, std::move(copy), SimpleVectorStats<T>{});
250 }
251
252 return std::make_shared<ConstantVector<T>>(
253 pool, size, index, std::move(vector), SimpleVectorStats<T>{});
254}
255
256// static
257VectorPtr BaseVector::wrapInConstant(

Callers

nothing calls this directly

Calls 11

indicesMethod · 0.80
createFunction · 0.70
poolMethod · 0.45
isNullAtMethod · 0.45
typeMethod · 0.45
setNullMethod · 0.45
valueAtMethod · 0.45
indexMethod · 0.45
encodingMethod · 0.45
copyMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected