| 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()); |
nothing calls this directly
no test coverage detected