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

Method apply

bolt/functions/lib/ArraySort.cpp:352–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

350 explicit ArraySortLambdaFunction(bool ascending, bool throwOnNestedNull)
351 : ascending_{ascending}, throwOnNestedNull_(throwOnNestedNull) {}
352
353 void apply(
354 const SelectivityVector& rows,
355 std::vector<VectorPtr>& args,
356 const TypePtr& /*outputType*/,
357 exec::EvalCtx& context,
358 VectorPtr& result) const override {
359 // Flatten input array.
360 exec::LocalDecodedVector arrayDecoder(context, *args[0], rows);
361 auto& decodedArray = *arrayDecoder.get();
362
363 auto flatArray = flattenArray(rows, args[0], decodedArray);
364
365 std::vector<VectorPtr> lambdaArgs = {flatArray->elements()};
366 auto newNumElements = flatArray->elements()->size();
367
368 SelectivityVector validRowsInReusedResult =
369 toElementRows<ArrayVector>(newNumElements, rows, flatArray.get());
370
371 // Compute sorting keys.
372 VectorPtr newElements;
373
374 auto elementToTopLevelRows = getElementToTopLevelRows(
375 newNumElements, rows, flatArray.get(), context.pool());
376
377 // Loop over lambda functions and apply these to elements of the base array.
378 // In most cases there will be only one function and the loop will run once.
379 auto it = args[1]->asUnchecked<FunctionVector>()->iterator(&rows);
380 while (auto entry = it.next()) {
381 auto elementRows = toElementRows<ArrayVector>(
382 newNumElements, *entry.rows, flatArray.get());
383 auto wrapCapture = toWrapCapture<ArrayVector>(
384 newNumElements, entry.callable, *entry.rows, flatArray);
385
386 entry.callable->apply(
387 elementRows,
388 &validRowsInReusedResult,
389 wrapCapture,
390 &context,
391 lambdaArgs,
392 elementToTopLevelRows,
393 &newElements);
394 }
395
396 // Sort 'newElements'.
397 auto indices = sortElements(
398 rows,
399 *flatArray,
400 *newElements,
401 ascending_,
402 false /*nullsFirst*/,
403 context,
404 throwOnNestedNull_);
405 auto sortedElements = BaseVector::wrapInDictionary(
406 nullptr,
407 indices,
408 indices->size() / sizeof(vector_size_t),
409 flatArray->elements());

Callers

nothing calls this directly

Calls 13

flattenArrayFunction · 0.85
sortElementsFunction · 0.85
wrapInDictionaryFunction · 0.85
iteratorMethod · 0.80
getElementToTopLevelRowsFunction · 0.70
getMethod · 0.45
sizeMethod · 0.45
poolMethod · 0.45
nextMethod · 0.45
applyMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected