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

Function MapToSchemaField

cpp/src/parquet/arrow/schema.cc:621–704  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

619 SchemaField* out);
620
621Status MapToSchemaField(const GroupNode& group, LevelInfo current_levels,
622 SchemaTreeContext* ctx, const SchemaField* parent,
623 SchemaField* out) {
624 if (group.field_count() != 1) {
625 return Status::Invalid("MAP-annotated groups must have a single child.");
626 }
627 // MAP-annotated groups cannot be repeated unless served as an element within a
628 // LIST-annotated group with 2-level structure.
629 if (group.is_repeated() &&
630 (group.parent() == nullptr || !group.parent()->logical_type()->is_list())) {
631 return Status::Invalid("MAP-annotated groups must not be repeated.");
632 }
633
634 const Node& key_value_node = *group.field(0);
635
636 if (!key_value_node.is_repeated()) {
637 return Status::Invalid(
638 "Non-repeated key value in a MAP-annotated group are not supported.");
639 }
640
641 if (!key_value_node.is_group()) {
642 return Status::Invalid("Key-value node must be a group.");
643 }
644
645 const GroupNode& key_value = checked_cast<const GroupNode&>(key_value_node);
646 if (key_value.field_count() != 1 && key_value.field_count() != 2) {
647 return Status::Invalid("Key-value map node must have 1 or 2 child elements. Found: ",
648 key_value.field_count());
649 }
650 const Node& key_node = *key_value.field(0);
651 if (!key_node.is_required()) {
652 return Status::Invalid("Map keys must be annotated as required.");
653 }
654 // Arrow doesn't support 1 column maps (i.e. Sets). The options are to either
655 // make the values column nullable, or process the map as a list. We choose the
656 // latter as it is simpler.
657 if (key_value.field_count() == 1) {
658 return ListToSchemaField(group, current_levels, ctx, parent, out);
659 }
660
661 if (group.is_optional()) {
662 current_levels.IncrementOptional();
663 }
664 int16_t repeated_ancestor_def_level = current_levels.IncrementRepeated();
665
666 out->children.resize(1);
667 SchemaField* key_value_field = &out->children[0];
668
669 key_value_field->children.resize(2);
670 SchemaField* key_field = &key_value_field->children[0];
671 SchemaField* value_field = &key_value_field->children[1];
672
673 ctx->LinkParent(out, parent);
674 ctx->LinkParent(key_value_field, out);
675 ctx->LinkParent(key_field, key_value_field);
676 ctx->LinkParent(value_field, key_value_field);
677
678 // required/optional group name=whatever {

Callers 2

ResolveListFunction · 0.85
GroupToSchemaFieldFunction · 0.85

Calls 13

ListToSchemaFieldFunction · 0.85
NodeToSchemaFieldFunction · 0.85
struct_Function · 0.85
is_listMethod · 0.80
resizeMethod · 0.80
LinkParentMethod · 0.80
fieldFunction · 0.70
FieldIdMetadataFunction · 0.70
InvalidFunction · 0.50
OKFunction · 0.50
parentMethod · 0.45
fieldMethod · 0.45

Tested by

no test coverage detected