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

Function NodeToSchemaField

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

Source from the content-addressed store, hash-verified

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

Callers 4

GroupToStructFunction · 0.85
MapToSchemaFieldFunction · 0.85
ResolveListFunction · 0.85
MakeMethod · 0.85

Calls 11

GroupToSchemaFieldFunction · 0.85
GetTypeForNodeFunction · 0.85
PopulateLeafFunction · 0.85
LinkParentMethod · 0.80
resizeMethod · 0.80
ARROW_ASSIGN_OR_RAISEFunction · 0.70
fieldFunction · 0.70
FieldIdMetadataFunction · 0.70
OKFunction · 0.50
GetColumnIndexMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected