| 880 | } |
| 881 | |
| 882 | Status NodeToSchemaField(const Node& node, LevelInfo current_levels, |
| 883 | SchemaTreeContext* ctx, const SchemaField* parent, |
| 884 | SchemaField* out) { |
| 885 | // Workhorse function for converting a Parquet schema node to an Arrow |
| 886 | // type. Handles different conventions for nested data. |
| 887 | |
| 888 | ctx->LinkParent(out, parent); |
| 889 | |
| 890 | // Now, walk the schema and create a ColumnDescriptor for each leaf node |
| 891 | if (node.is_group()) { |
| 892 | // A nested field, but we don't know what kind yet |
| 893 | return GroupToSchemaField(static_cast<const GroupNode&>(node), current_levels, ctx, |
| 894 | parent, out); |
| 895 | } else { |
| 896 | // Either a normal flat primitive type, or a list type encoded with 1-level |
| 897 | // list encoding. Note that the 3-level encoding is the form recommended by |
| 898 | // the parquet specification, but technically we can have either |
| 899 | // |
| 900 | // required/optional $TYPE $FIELD_NAME |
| 901 | // |
| 902 | // or |
| 903 | // |
| 904 | // repeated $TYPE $FIELD_NAME |
| 905 | const auto& primitive_node = static_cast<const PrimitiveNode&>(node); |
| 906 | int column_index = ctx->schema->GetColumnIndex(primitive_node); |
| 907 | ARROW_ASSIGN_OR_RAISE(std::shared_ptr<ArrowType> type, |
| 908 | GetTypeForNode(column_index, primitive_node, ctx)); |
| 909 | if (node.is_repeated()) { |
| 910 | // One-level list encoding, e.g. |
| 911 | // a: repeated int32; |
| 912 | int16_t repeated_ancestor_def_level = current_levels.IncrementRepeated(); |
| 913 | out->children.resize(1); |
| 914 | auto child_field = ::arrow::field(node.name(), type, /*nullable=*/false); |
| 915 | RETURN_NOT_OK(PopulateLeaf(column_index, child_field, current_levels, ctx, out, |
| 916 | &out->children[0])); |
| 917 | |
| 918 | ARROW_ASSIGN_OR_RAISE(auto list_type, |
| 919 | MakeArrowList(out->children[0].field, ctx->properties)); |
| 920 | out->field = ::arrow::field(node.name(), std::move(list_type), |
| 921 | /*nullable=*/false, FieldIdMetadata(node.field_id())); |
| 922 | out->level_info = current_levels; |
| 923 | // At this point current_levels has consider this list the ancestor so restore |
| 924 | // the actual ancestor. |
| 925 | out->level_info.repeated_ancestor_def_level = repeated_ancestor_def_level; |
| 926 | return Status::OK(); |
| 927 | } else { |
| 928 | current_levels.Increment(node); |
| 929 | // A normal (required/optional) primitive node |
| 930 | return PopulateLeaf(column_index, |
| 931 | ::arrow::field(node.name(), type, node.is_optional(), |
| 932 | FieldIdMetadata(node.field_id())), |
| 933 | current_levels, ctx, parent, out); |
| 934 | } |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | // Get the original Arrow schema, as serialized in the Parquet metadata |
| 939 | Status GetOriginSchema(const std::shared_ptr<const KeyValueMetadata>& metadata, |
no test coverage detected