| 197 | } |
| 198 | |
| 199 | static 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 | |
| 242 | static void sinkFunc(ExportFuncSharedState& sharedState, ExportFuncLocalState& localState, |
| 243 | const ExportFuncBindData& bindData, std::vector<std::shared_ptr<ValueVector>> inputVectors) { |
no test coverage detected