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

Method applyArray

bolt/expression/CastExpr.cpp:183–250  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183VectorPtr 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,

Callers

nothing calls this directly

Calls 13

toElementRowsFunction · 0.85
applyFunction · 0.85
ARRAYFunction · 0.85
swapErrorsMethod · 0.80
rawSizesMethod · 0.80
applyToSelectedMethod · 0.80
getElementToTopLevelRowsFunction · 0.50
sizeMethod · 0.45
poolMethod · 0.45
resizeMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected