MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / writeRows

Function writeRows

src/function/export/export_csv_function.cpp:199–240  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

197}
198
199static void writeRows(const ExportCSVBindData& exportCSVBindData, ExportCSVLocalState& localState,
200 ExportCSVSharedState& sharedState, std::vector<std::shared_ptr<ValueVector>> inputVectors) {
201 auto& exportCSVLocalState = localState.cast<ExportCSVLocalState>();
202 auto& castVectors = localState.castVectors;
203 auto& serializer = localState.serializer;
204 for (auto i = 0u; i < inputVectors.size(); i++) {
205 auto vectorToCast = {inputVectors[i]};
206 exportCSVLocalState.castFuncs[i](vectorToCast,
207 common::SelectionVector::fromValueVectors(vectorToCast), *castVectors[i],
208 castVectors[i]->getSelVectorPtr(), nullptr /* dataPtr */);
209 }
210
211 uint64_t numRowsToWrite = 1;
212 for (auto& vectorToCast : inputVectors) {
213 if (!vectorToCast->state->isFlat()) {
214 numRowsToWrite = vectorToCast->state->getSelVector().getSelSize();
215 break;
216 }
217 }
218 for (auto i = 0u; i < numRowsToWrite; i++) {
219 for (auto j = 0u; j < castVectors.size(); j++) {
220 if (j != 0) {
221 serializer->writeBufferData(exportCSVBindData.exportOption.delimiter);
222 }
223 auto vector = castVectors[j];
224 auto pos = vector->state->isFlat() ? vector->state->getSelVector()[0] :
225 vector->state->getSelVector()[i];
226 if (vector->isNull(pos)) {
227 // write null value
228 serializer->writeBufferData(ExportCSVConstants::DEFAULT_NULL_STR);
229 continue;
230 }
231 auto strValue = vector->getValue<string_t>(pos);
232 // Note: we need blindly add quotes to LIST.
233 writeString(serializer.get(), exportCSVBindData, strValue.getData(), strValue.len,
234 ExportCSVConstants::DEFAULT_FORCE_QUOTE ||
235 inputVectors[j]->dataType.getLogicalTypeID() == LogicalTypeID::LIST,
236 sharedState.parallelFlag);
237 }
238 serializer->writeBufferData(ExportCSVConstants::DEFAULT_CSV_NEWLINE[0]);
239 }
240}
241
242static void sinkFunc(ExportFuncSharedState& sharedState, ExportFuncLocalState& localState,
243 const ExportFuncBindData& bindData, std::vector<std::shared_ptr<ValueVector>> inputVectors) {

Callers 2

writeHeaderMethod · 0.85
sinkFuncFunction · 0.85

Calls 9

writeStringFunction · 0.85
getSelSizeMethod · 0.80
getValue<string_t>Method · 0.80
getLogicalTypeIDMethod · 0.80
sizeMethod · 0.45
isFlatMethod · 0.45
isNullMethod · 0.45
getMethod · 0.45
getDataMethod · 0.45

Tested by

no test coverage detected