Repository: apache/arrow
File: cpp/src/parquet/arrow/schema.cc (C++)

Code before:
        (group.parent() == nullptr || !group.parent()->logical_type()->is_list())) {
      return Status::Invalid("LIST-annotated groups must not be repeated.");
    }
    return {};
  };

  SchemaField* child_field = &out->children[0];

  if (list_node.is_group()) {
    const auto& list_group = static_cast<const GroupNode&>(list_node);
    if (list_group.field_count() > 1) {
      // The inner type of the list should be a struct when there are multiple fields
      // in the repeated group
      RETURN_NOT_OK(check_two_level_list_repeated(group));
      return GroupToStruct(list_group, current_levels, ctx, out, child_field);
    }
    if (list_group.field_count() == 0) {
      return Status::Invalid("Group must have at least one child.");
    }

    if (list_group.logical_type()->is_none() && HasListElementName(list_group, group)) {
      // Rule 4 at
      // https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#backward-compatibility-rules
      //
      // required/optional group name=SOMETHING {
      //   repeated group name=array or $SOMETHING_tuple {
      //     required/optional TYPE item;
      //   }
      // }
      //
      // The inner type of the list should be a struct rather than a primitive value
      //
      // yields list<item: struct<item: TYPE ?nullable> not null> ?nullable
      RETURN_NOT_OK(check_two_level_list_repeated(group));
      return GroupToStruct(list_group, current_levels, ctx, out, child_field);
    }

    const auto& repeated_field = list_group.field(0);
    if (!list_group.logical_type()->is_none() || repeated_field->is_repeated()) {
      RETURN_NOT_OK(check_two_level_list_repeated(group));
      if (list_group.logical_type()->is_list()) {
        // Special case where the inner type might be a list with two-level encoding
        // like below:
        //
        // required/optional group name=SOMETHING (LIST) {
        //   repeated group array (LIST) {
        //     repeated TYPE item;
        //   }
        // }
        //
        // yields list<item: list<item: TYPE not null> not null> ?nullable

Review comment (suggestion):
Now this is more strict than before because of the additional logical type check.

Code after:
        (group.parent() == nullptr || !group.parent()->logical_type()->is_list())) {
      return Status::Invalid("LIST-annotated groups must not be repeated.");
    }
    return {};
  };

  SchemaField* child_field = &out->children[0];
  const Node& list_node = *group.field(0);
  if (!list_node.is_repeated()) {
    return Status::Invalid(
        "Non-repeated nodes in a LIST-annotated group are not supported.");
  }

  if (list_node.is_group()) {
    const auto& list_group = static_cast<const GroupNode&>(list_node);
    if (list_group.field_count() > 1) {
      // The inner type of the list should be a struct when there are multiple fields
      // in the repeated group
      RETURN_NOT_OK(check_two_level_list_repetition(group));
      return GroupToStruct(list_group, current_levels, ctx, out, child_field);
    }
    if (list_group.field_count() == 0) {
      return Status::Invalid("Group must have at least one child.");
    }

    if (list_group.logical_type()->is_none() && HasListElementName(list_group, group)) {
      // Rule 4 at
      // https://github.com/apache/parquet-format/blob/master/LogicalTypes.md#backward-compatibility-rules
      //
      // required/optional group name=SOMETHING {
      //   repeated group name=array or $SOMETHING_tuple {
      //     required/optional TYPE item;
      //   }
      // }
      //
      // The inner type of the list should be a struct rather than a primitive value
      //
      // yields list<item: struct<item: TYPE ?nullable> not null> ?nullable
      RETURN_NOT_OK(check_two_level_list_repetition(group));
      return GroupToStruct(list_group, current_levels, ctx, out, child_field);
    }

    const auto& repeated_field = list_group.field(0);
    if (!list_group.logical_type()->is_none() || repeated_field->is_repeated()) {
      RETURN_NOT_OK(check_two_level_list_repetition(group));
      if (list_group.logical_type()->is_list()) {
        // Special case where the inner type might be a list with two-level encoding
        // like below:
        //
        // required/optional group name=SOMETHING (LIST) {
        //   repeated group array (LIST) {