MCPcopy Create free account
hub / github.com/apache/arrow / TryConvertChunk

Method TryConvertChunk

cpp/src/arrow/csv/column_builder.cc:269–328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

267}
268
269Status InferringColumnBuilder::TryConvertChunk(int64_t chunk_index) {
270 std::unique_lock<std::mutex> lock(mutex_);
271 std::shared_ptr<Converter> converter = converter_;
272 std::shared_ptr<BlockParser> parser = parsers_[chunk_index];
273 InferKind kind = infer_status_.kind();
274
275 if (chunks_[chunk_index] && chunk_kinds_[chunk_index] == kind) {
276 // Already tried, nothing to do
277 return Status::OK();
278 }
279
280 DCHECK_NE(parser, nullptr) << " for chunk_index " << chunk_index;
281
282 lock.unlock();
283 auto maybe_array = converter->Convert(*parser, col_index_);
284 lock.lock();
285
286 if (kind != infer_status_.kind()) {
287 // infer_kind_ was changed by another task, reconvert
288 lock.unlock();
289 ScheduleConvertChunk(chunk_index);
290 return Status::OK();
291 }
292
293 if (maybe_array.ok() || !infer_status_.can_loosen_type()) {
294 // Conversion succeeded, or failed definitively
295 if (!infer_status_.can_loosen_type()) {
296 // We won't try to reconvert anymore
297 parsers_[chunk_index].reset();
298 }
299 chunk_kinds_[chunk_index] = kind;
300 return SetChunkUnlocked(chunk_index, maybe_array);
301 }
302
303 // Conversion failed, try another type
304 infer_status_.LoosenType(maybe_array.status());
305 RETURN_NOT_OK(UpdateType());
306 kind = infer_status_.kind();
307
308 // Reconvert past finished chunks
309 // (unfinished chunks will notice by themselves if they need reconverting)
310 const auto nchunks = static_cast<int64_t>(chunks_.size());
311 std::vector<int64_t> chunks_to_reconvert;
312 for (int64_t i = 0; i < nchunks; ++i) {
313 if (i != chunk_index && chunks_[i] && chunk_kinds_[i] != kind) {
314 // That chunk was converted using the wrong type
315 chunks_[i].reset();
316 chunk_kinds_[i].reset();
317 chunks_to_reconvert.push_back(i);
318 }
319 }
320 // Reconvert this chunk too
321 chunks_to_reconvert.push_back(chunk_index);
322
323 lock.unlock();
324 for (auto i : chunks_to_reconvert) {
325 ScheduleConvertChunk(i);
326 }

Callers

nothing calls this directly

Calls 10

can_loosen_typeMethod · 0.80
LoosenTypeMethod · 0.80
push_backMethod · 0.80
OKFunction · 0.50
kindMethod · 0.45
ConvertMethod · 0.45
okMethod · 0.45
resetMethod · 0.45
statusMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected