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

Function ResolveList

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

Source from the content-addressed store, hash-verified

707}
708
709Status ResolveList(const GroupNode& group, LevelInfo current_levels,
710 SchemaTreeContext* ctx, SchemaField* out) {
711 auto check_two_level_list_repetition = [](const GroupNode& group) -> Status {
712 // When it is repeated, the LIST-annotated 2-level structure can only serve as an
713 // element within another LIST-annotated 2-level structure.
714 if (group.is_repeated() &&
715 (group.parent() == nullptr || !group.parent()->logical_type()->is_list())) {
716 return Status::Invalid("LIST-annotated groups must not be repeated.");
717 }
718 return {};
719 };
720
721 SchemaField* child_field = &out->children[0];
722 const Node& list_node = *group.field(0);
723 if (!list_node.is_repeated()) {
724 return Status::Invalid(
725 "Non-repeated nodes in a LIST-annotated group are not supported.");
726 }
727
728 if (list_node.is_group()) {
729 const auto& list_group = static_cast<const GroupNode&>(list_node);
730 if (list_group.field_count() > 1) {
731 // The inner type of the list should be a struct when there are multiple fields
732 // in the repeated group
733 RETURN_NOT_OK(check_two_level_list_repetition(group));
734 return GroupToStruct(list_group, current_levels, ctx, out, child_field);
735 }
736 if (list_group.field_count() == 0) {
737 return Status::Invalid("Group must have at least one child.");
738 }
739
740 if (list_group.logical_type()->is_none() && HasListElementName(list_group, group)) {
741 // Rule 4 at
742 // https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#backward-compatibility-rules
743 //
744 // required/optional group name=SOMETHING {
745 // repeated group name=array or $SOMETHING_tuple {
746 // required/optional TYPE item;
747 // }
748 // }
749 //
750 // The inner type of the list should be a struct rather than a primitive value
751 //
752 // yields list<item: struct<item: TYPE ?nullable> not null> ?nullable
753 RETURN_NOT_OK(check_two_level_list_repetition(group));
754 return GroupToStruct(list_group, current_levels, ctx, out, child_field);
755 }
756
757 const auto& repeated_field = list_group.field(0);
758 if (!list_group.logical_type()->is_none() || repeated_field->is_repeated()) {
759 RETURN_NOT_OK(check_two_level_list_repetition(group));
760 if (list_group.logical_type()->is_list()) {
761 // Special case where the inner type might be a list with two-level encoding
762 // like below:
763 //
764 // required/optional group name=SOMETHING (LIST) {
765 // repeated group array (LIST) {
766 // repeated TYPE item;

Callers 1

ListToSchemaFieldFunction · 0.85

Calls 15

GroupToStructFunction · 0.85
HasListElementNameFunction · 0.85
ListToSchemaFieldFunction · 0.85
MapToSchemaFieldFunction · 0.85
NodeToSchemaFieldFunction · 0.85
GetTypeForNodeFunction · 0.85
PopulateLeafFunction · 0.85
is_listMethod · 0.80
is_noneMethod · 0.80
is_mapMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
fieldFunction · 0.70

Tested by

no test coverage detected