| 181 | } |
| 182 | |
| 183 | VectorPtr CastExpr::applyArray( |
| 184 | const SelectivityVector& rows, |
| 185 | const ArrayVector* input, |
| 186 | exec::EvalCtx& context, |
| 187 | const ArrayType& fromType, |
| 188 | const ArrayType& toType) { |
| 189 | // Cast input array elements to output array elements based on their types |
| 190 | // using their linear selectivity vector |
| 191 | auto arrayElements = input->elements(); |
| 192 | |
| 193 | auto nestedRows = |
| 194 | functions::toElementRows(arrayElements->size(), rows, input); |
| 195 | auto elementToTopLevelRows = functions::getElementToTopLevelRows( |
| 196 | arrayElements->size(), rows, input, context.pool()); |
| 197 | |
| 198 | ErrorVectorPtr oldErrors; |
| 199 | context.swapErrors(oldErrors); |
| 200 | |
| 201 | VectorPtr newElements; |
| 202 | { |
| 203 | ScopedVarSetter holder(&inTopLevel, false); |
| 204 | apply( |
| 205 | nestedRows, |
| 206 | arrayElements, |
| 207 | context, |
| 208 | fromType.elementType(), |
| 209 | toType.elementType(), |
| 210 | newElements); |
| 211 | } |
| 212 | |
| 213 | // Returned array vector should be addressable for every element, even those |
| 214 | // that are not selected. |
| 215 | BufferPtr sizes = input->sizes(); |
| 216 | if (newElements->isConstantEncoding()) { |
| 217 | // If the newElements we extends its size since that is cheap. |
| 218 | newElements->resize(input->elements()->size()); |
| 219 | } else if (newElements->size() < input->elements()->size()) { |
| 220 | sizes = |
| 221 | AlignedBuffer::allocate<vector_size_t>(rows.end(), context.pool(), 0); |
| 222 | auto* inputSizes = input->rawSizes(); |
| 223 | auto* rawSizes = sizes->asMutable<vector_size_t>(); |
| 224 | rows.applyToSelected( |
| 225 | [&](vector_size_t row) { rawSizes[row] = inputSizes[row]; }); |
| 226 | } |
| 227 | |
| 228 | VectorPtr result = std::make_shared<ArrayVector>( |
| 229 | context.pool(), |
| 230 | ARRAY(toType.elementType()), |
| 231 | input->nulls(), |
| 232 | rows.end(), |
| 233 | input->offsets(), |
| 234 | sizes, |
| 235 | newElements); |
| 236 | |
| 237 | #ifndef SPARK_COMPATIBLE |
| 238 | propagateErrorsOrSetNulls( |
| 239 | setNullInResultAtError(), |
| 240 | context, |
nothing calls this directly
no test coverage detected