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

Function MakeChunkedArrayBuilder

cpp/src/arrow/json/chunked_builder.cc:439–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

437};
438
439Status MakeChunkedArrayBuilder(const std::shared_ptr<TaskGroup>& task_group,
440 MemoryPool* pool, const PromotionGraph* promotion_graph,
441 const std::shared_ptr<DataType>& type,
442 bool allow_promotion,
443 std::shared_ptr<ChunkedArrayBuilder>* out) {
444 // If a promotion graph is provided, unexpected fields will be allowed - using the graph
445 // recursively for itself and any child fields (via the `allow_promotion` parameter).
446 // Fields provided in the schema will adhere to their corresponding type. However,
447 // structs defined in the schema may obtain unexpected child fields, which will use the
448 // promotion graph as well.
449 //
450 // If a promotion graph is not provided, unexpected fields are always ignored and
451 // type inference never occurs.
452 if (type->id() == Type::STRUCT) {
453 std::vector<std::pair<std::string, std::shared_ptr<ChunkedArrayBuilder>>>
454 child_builders;
455 for (const auto& f : type->fields()) {
456 std::shared_ptr<ChunkedArrayBuilder> child_builder;
457 RETURN_NOT_OK(MakeChunkedArrayBuilder(task_group, pool, promotion_graph, f->type(),
458 allow_promotion, &child_builder));
459 child_builders.emplace_back(f->name(), std::move(child_builder));
460 }
461 *out = std::make_shared<ChunkedStructArrayBuilder>(task_group, pool, promotion_graph,
462 std::move(child_builders));
463 return Status::OK();
464 }
465 if (type->id() == Type::LIST) {
466 const auto& list_type = checked_cast<const ListType&>(*type);
467 std::shared_ptr<ChunkedArrayBuilder> value_builder;
468 RETURN_NOT_OK(MakeChunkedArrayBuilder(task_group, pool, promotion_graph,
469 list_type.value_type(), allow_promotion,
470 &value_builder));
471 *out = std::make_shared<ChunkedListArrayBuilder>(
472 task_group, pool, std::move(value_builder), list_type.value_field());
473 return Status::OK();
474 }
475
476 // Construct the "leaf" builder
477 std::shared_ptr<Converter> converter;
478 RETURN_NOT_OK(MakeConverter(type, pool, &converter));
479 if (allow_promotion && promotion_graph) {
480 *out = std::make_shared<InferringChunkedArrayBuilder>(task_group, promotion_graph,
481 std::move(converter));
482 } else {
483 *out = std::make_shared<TypedChunkedArrayBuilder>(task_group, std::move(converter));
484 }
485 return Status::OK();
486}
487
488} // namespace
489

Callers 5

MakeBuilderMethod · 0.85
operator()Method · 0.85
ParseOneFunction · 0.85
InsertChildrenMethod · 0.85
TESTFunction · 0.85

Calls 8

emplace_backMethod · 0.80
OKFunction · 0.70
MakeConverterFunction · 0.70
idMethod · 0.45
fieldsMethod · 0.45
typeMethod · 0.45
nameMethod · 0.45
value_typeMethod · 0.45

Tested by 1

TESTFunction · 0.68