| 48 | } |
| 49 | |
| 50 | void apply( |
| 51 | const SelectivityVector& rows, |
| 52 | std::vector<VectorPtr>& args, |
| 53 | const TypePtr& outputType, |
| 54 | exec::EvalCtx& context, |
| 55 | VectorPtr& result) const override { |
| 56 | BOLT_CHECK_EQ(args.size(), 2); |
| 57 | |
| 58 | // Flatten input map. |
| 59 | exec::LocalDecodedVector mapDecoder(context, *args[0], rows); |
| 60 | auto& decodedMap = *mapDecoder.get(); |
| 61 | |
| 62 | auto flatMap = flattenMap(rows, args[0], decodedMap); |
| 63 | |
| 64 | std::vector<VectorPtr> lambdaArgs = { |
| 65 | flatMap->mapKeys(), flatMap->mapValues()}; |
| 66 | auto numValues = flatMap->mapValues()->size(); |
| 67 | |
| 68 | SelectivityVector validRowsInReusedResult = |
| 69 | toElementRows<MapVector>(numValues, rows, flatMap.get()); |
| 70 | |
| 71 | VectorPtr transformedValues; |
| 72 | |
| 73 | auto elementToTopLevelRows = getElementToTopLevelRows( |
| 74 | numValues, rows, flatMap.get(), context.pool()); |
| 75 | |
| 76 | // Loop over lambda functions and apply these to values of the map. |
| 77 | // In most cases there will be only one function and the loop will run once. |
| 78 | auto it = args[1]->asUnchecked<FunctionVector>()->iterator(&rows); |
| 79 | while (auto entry = it.next()) { |
| 80 | auto valueRows = |
| 81 | toElementRows<MapVector>(numValues, *entry.rows, flatMap.get()); |
| 82 | auto wrapCapture = toWrapCapture<MapVector>( |
| 83 | numValues, entry.callable, *entry.rows, flatMap); |
| 84 | |
| 85 | entry.callable->apply( |
| 86 | valueRows, |
| 87 | &validRowsInReusedResult, |
| 88 | wrapCapture, |
| 89 | &context, |
| 90 | lambdaArgs, |
| 91 | elementToTopLevelRows, |
| 92 | &transformedValues); |
| 93 | } |
| 94 | |
| 95 | // Set nulls for rows not present in 'rows'. |
| 96 | BufferPtr newNulls = addNullsForUnselectedRows(flatMap, rows); |
| 97 | |
| 98 | auto localResult = std::make_shared<MapVector>( |
| 99 | flatMap->pool(), |
| 100 | outputType, |
| 101 | std::move(newNulls), |
| 102 | flatMap->size(), |
| 103 | flatMap->offsets(), |
| 104 | flatMap->sizes(), |
| 105 | flatMap->mapKeys(), |
| 106 | transformedValues); |
| 107 | context.moveOrCopyResult(localResult, rows, result); |
nothing calls this directly
no test coverage detected