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

Method DoInspect

cpp/src/arrow/dataset/partition.cc:464–522  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

462 }
463
464 Result<std::shared_ptr<Schema>> DoInspect() {
465 dictionaries_.assign(name_to_index_.size(), nullptr);
466
467 std::vector<std::shared_ptr<Field>> fields(name_to_index_.size());
468 if (options_.schema) {
469 const auto requested_size = options_.schema->fields().size();
470 const auto inferred_size = fields.size();
471 if (inferred_size != requested_size) {
472 return Status::Invalid("Requested schema has ", requested_size,
473 " fields, but only ", inferred_size, " were detected");
474 }
475 }
476
477 for (const auto& name_index : name_to_index_) {
478 const auto& name = name_index.first;
479 auto index = name_index.second;
480
481 std::shared_ptr<ArrayData> reprs;
482 RETURN_NOT_OK(repr_memos_[index]->GetArrayData(0, &reprs));
483
484 if (reprs->length == 0) {
485 return Status::Invalid("No non-null segments were available for field '", name,
486 "'; couldn't infer type");
487 }
488
489 std::shared_ptr<Field> current_field;
490 std::shared_ptr<Array> dict;
491 if (options_.schema) {
492 // if we have a schema, use the schema type.
493 current_field = options_.schema->field(index);
494 auto cast_target = current_field->type();
495 if (is_dictionary(cast_target->id())) {
496 cast_target = checked_pointer_cast<DictionaryType>(cast_target)->value_type();
497 }
498 auto maybe_dict = compute::Cast(reprs, cast_target);
499 if (!maybe_dict.ok()) {
500 return Status::Invalid("Could not cast segments for partition field ",
501 current_field->name(), " to requested type ",
502 current_field->type()->ToString(),
503 " because: ", maybe_dict.status());
504 }
505 dict = maybe_dict.ValueOrDie().make_array();
506 } else {
507 // try casting to int32, otherwise bail and just use the string reprs
508 dict = compute::Cast(reprs, int32()).ValueOr(reprs).make_array();
509 auto type = dict->type();
510 if (options_.infer_dictionary) {
511 // wrap the inferred type in dictionary()
512 type = dictionary(int32(), std::move(type));
513 }
514 current_field = field(name, std::move(type));
515 }
516 fields[index] = std::move(current_field);
517 dictionaries_[index] = std::move(dict);
518 }
519
520 Reset();
521 return ::arrow::schema(std::move(fields));

Callers

nothing calls this directly

Calls 15

CastFunction · 0.85
assignMethod · 0.80
make_arrayMethod · 0.80
ValueOrDieMethod · 0.80
ValueOrMethod · 0.80
InvalidFunction · 0.50
is_dictionaryFunction · 0.50
dictionaryFunction · 0.50
fieldFunction · 0.50
ResetFunction · 0.50
schemaFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected