// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements.  See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership.  The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License.  You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package schema

import (
	
	
	
	

	
	
	
	format 
)

type taggedInfo struct {
	Name string

	Type      parquet.Type
	KeyType   parquet.Type
	ValueType parquet.Type

	Length      int32
	KeyLength   int32
	ValueLength int32

	Scale      int32
	KeyScale   int32
	ValueScale int32

	Precision      int32
	KeyPrecision   int32
	ValuePrecision int32

	FieldID      int32
	KeyFieldID   int32
	ValueFieldID int32

	RepetitionType  parquet.Repetition
	ValueRepetition parquet.Repetition

	Converted      ConvertedType
	KeyConverted   ConvertedType
	ValueConverted ConvertedType

	LogicalFields      map[string]string
	KeyLogicalFields   map[string]string
	ValueLogicalFields map[string]string

	LogicalType      LogicalType
	KeyLogicalType   LogicalType
	ValueLogicalType LogicalType

	Exclude bool
}

func ( *taggedInfo) () ( taggedInfo) {
	 = *
	.Type = .KeyType
	.Length = .KeyLength
	.Scale = .KeyScale
	.Precision = .KeyPrecision
	.FieldID = .KeyFieldID
	.RepetitionType = parquet.Repetitions.Required
	.Converted = .KeyConverted
	.LogicalType = .KeyLogicalType
	return
}

func ( *taggedInfo) () ( taggedInfo) {
	 = *
	.Type = .ValueType
	.Length = .ValueLength
	.Scale = .ValueScale
	.Precision = .ValuePrecision
	.FieldID = .ValueFieldID
	.RepetitionType = .ValueRepetition
	.Converted = .ValueConverted
	.LogicalType = .ValueLogicalType
	return
}

func ( *taggedInfo) () {
	 := func( map[string]string, ,  int32) LogicalType {
		,  := ["type"]
		if ! {
			return NoLogicalType{}
		}

		switch strings.ToLower() {
		case "string":
			return StringLogicalType{}
		case "map":
			return MapLogicalType{}
		case "list":
			return ListLogicalType{}
		case "enum":
			return EnumLogicalType{}
		case "decimal":
			if ,  := ["precision"];  {
				 = int32FromType()
			}
			if ,  := ["scale"];  {
				 = int32FromType()
			}
			return NewDecimalLogicalType(, )
		case "date":
			return DateLogicalType{}
		case "time":
			,  := ["unit"]
			if ! {
				panic("must specify unit for time logical type")
			}
			,  := ["isadjustedutc"]
			if ! {
				 = "true"
			}
			return NewTimeLogicalType(boolFromStr(), timeUnitFromString(strings.ToLower()))
		case "timestamp":
			,  := ["unit"]
			if ! {
				panic("must specify unit for time logical type")
			}
			,  := ["isadjustedutc"]
			if ! {
				 = "true"
			}
			return NewTimestampLogicalType(boolFromStr(), timeUnitFromString())
		case "integer":
			,  := ["bitwidth"]
			if ! {
				panic("must specify bitwidth if explicitly setting integer logical type")
			}
			,  := ["signed"]
			if ! {
				 = "true"
			}

			return NewIntLogicalType(int8(int32FromType()), boolFromStr())
		case "null":
			return NullLogicalType{}
		case "json":
			return JSONLogicalType{}
		case "bson":
			return BSONLogicalType{}
		case "uuid":
			return UUIDLogicalType{}
		case "float16":
			return Float16LogicalType{}
		default:
			panic(fmt.Errorf("invalid logical type specified: %s", ))
		}
	}

	.LogicalType = (.LogicalFields, .Precision, .Scale)
	.KeyLogicalType = (.KeyLogicalFields, .KeyPrecision, .KeyScale)
	.ValueLogicalType = (.ValueLogicalFields, .ValuePrecision, .ValueScale)
}

func newTaggedInfo() taggedInfo {
	return taggedInfo{
		Type:               parquet.Types.Undefined,
		KeyType:            parquet.Types.Undefined,
		ValueType:          parquet.Types.Undefined,
		RepetitionType:     parquet.Repetitions.Undefined,
		ValueRepetition:    parquet.Repetitions.Undefined,
		Converted:          ConvertedTypes.NA,
		KeyConverted:       ConvertedTypes.NA,
		ValueConverted:     ConvertedTypes.NA,
		FieldID:            -1,
		KeyFieldID:         -1,
		ValueFieldID:       -1,
		LogicalFields:      make(map[string]string),
		KeyLogicalFields:   make(map[string]string),
		ValueLogicalFields: make(map[string]string),
		LogicalType:        NoLogicalType{},
		KeyLogicalType:     NoLogicalType{},
		ValueLogicalType:   NoLogicalType{},
		Exclude:            false,
	}
}

var int32FromType = func( string) int32 {
	,  := strconv.Atoi()
	if  != nil {
		panic()
	}
	return int32()
}

var boolFromStr = func( string) bool {
	,  := strconv.ParseBool()
	if  != nil {
		panic()
	}
	return 
}

func infoFromTags( reflect.StructTag) *taggedInfo {
	 := func( string) parquet.Type {
		,  := format.TypeFromString(strings.ToUpper())
		if  != nil {
			panic(fmt.Errorf("invalid type specified: %s", ))
		}
		return parquet.Type()
	}

	 := func( string) parquet.Repetition {
		,  := format.FieldRepetitionTypeFromString(strings.ToUpper())
		if  != nil {
			panic()
		}
		return parquet.Repetition()
	}

	 := func( string) ConvertedType {
		,  := format.ConvertedTypeFromString(strings.ToUpper())
		if  != nil {
			panic()
		}
		return ConvertedType()
	}

	if ,  := .Lookup("parquet");  {
		 := newTaggedInfo()
		if  == "-" {
			.Exclude = true
			return &
		}
		for ,  := range strings.Split(strings.ReplaceAll(, "\t", ""), ",") {
			 = strings.TrimSpace()
			 := strings.SplitN(, "=", 2)
			 := strings.TrimSpace(strings.ToLower([0]))
			 := strings.TrimSpace([1])

			switch  {
			case "name":
				.Name = 
			case "type":
				.Type = ()
			case "keytype":
				.KeyType = ()
			case "valuetype":
				.ValueType = ()
			case "length":
				.Length = int32FromType()
			case "keylength":
				.KeyLength = int32FromType()
			case "valuelength":
				.ValueLength = int32FromType()
			case "scale":
				.Scale = int32FromType()
			case "keyscale":
				.KeyScale = int32FromType()
			case "valuescale":
				.ValueScale = int32FromType()
			case "precision":
				.Precision = int32FromType()
			case "keyprecision":
				.KeyPrecision = int32FromType()
			case "valueprecision":
				.ValuePrecision = int32FromType()
			case "fieldid":
				.FieldID = int32FromType()
			case "keyfieldid":
				.KeyFieldID = int32FromType()
			case "valuefieldid":
				.ValueFieldID = int32FromType()
			case "repetition":
				.RepetitionType = ()
			case "valuerepetition":
				.ValueRepetition = ()
			case "converted":
				.Converted = ()
			case "keyconverted":
				.KeyConverted = ()
			case "valueconverted":
				.ValueConverted = ()
			case "logical":
				.LogicalFields["type"] = 
			case "keylogical":
				.KeyLogicalFields["type"] = 
			case "valuelogical":
				.ValueLogicalFields["type"] = 
			default:
				switch {
				case strings.HasPrefix(, "logical."):
					.LogicalFields[strings.TrimPrefix(, "logical.")] = 
				case strings.HasPrefix(, "keylogical."):
					.KeyLogicalFields[strings.TrimPrefix(, "keylogical.")] = 
				case strings.HasPrefix(, "valuelogical."):
					.ValueLogicalFields[strings.TrimPrefix(, "valuelogical.")] = 
				}
			}
		}
		.UpdateLogicalTypes()
		return &
	}
	return nil
}

// typeToNode recursively converts a physical type and the tag info into parquet Nodes
//
// to avoid having to propagate errors up potentially high numbers of recursive calls
// we use panics and then recover in the public function NewSchemaFromStruct so that a
// failure very far down the stack quickly unwinds.
func typeToNode( string,  reflect.Type,  parquet.Repetition,  *taggedInfo) Node {
	// set up our default values for everything
	var (
		             = ConvertedTypes.None
		   LogicalType = NoLogicalType{}
		               = int32(-1)
		              = parquet.Types.Undefined
		               = 0
		             = 0
		                 = 0
	)
	if  != nil { // we have struct tag info to process
		 = .FieldID
		if .Converted != ConvertedTypes.NA {
			 = .Converted
		}
		 = .LogicalType
		 = .Type
		 = int(.Length)
		 = int(.Precision)
		 = int(.Scale)

		if .Name != "" {
			 = .Name
		}
		if .RepetitionType != parquet.Repetitions.Undefined {
			 = .RepetitionType
		}
	}

	// simplify the logic by switching based on the reflection Kind
	switch .Kind() {
	case reflect.Map:
		// a map must have a logical type of MAP or have no tag for logical type in which case
		// we assume MAP logical type.
		if !.IsNone() && !.Equals(MapLogicalType{}) {
			panic("cannot set logical type to something other than map for a map")
		}

		 := newTaggedInfo()
		if  != nil { // populate any value specific tags to propagate for the value type
			 = .CopyForValue()
		}

		// create the node for the value type of the map
		 := ("value", .Elem(), parquet.Repetitions.Required, &)
		if  != nil { // change our copy to now use the key specific tags if they exist
			 = .CopyForKey()
		}

		// create the node for the key type of the map
		 := ("key", .Key(), parquet.Repetitions.Required, &)
		if .RepetitionType() != parquet.Repetitions.Required { // key cannot be optional
			panic("key type of map must be Required")
		}
		return Must(MapOf(, , , , ))
	case reflect.Struct:
		if  == reflect.TypeOf(float16.Num{}) {
			return MustPrimitive(NewPrimitiveNodeLogical(, , Float16LogicalType{}, parquet.Types.FixedLenByteArray, 2, ))
		}
		// structs are Group nodes
		 := make(FieldList, 0)
		for  := 0;  < .NumField(); ++ {
			 := .Field()
			 := infoFromTags(.Tag)
			if  == nil || !.Exclude {
				 = append(, (.Name, .Type, parquet.Repetitions.Required, ))
			}
		}
		// group nodes don't have a physical type
		if  != parquet.Types.Undefined {
			panic("cannot specify custom type on struct")
		}
		// group nodes don't have converted or logical types
		if  != ConvertedTypes.None {
			panic("cannot specify converted types for a struct")
		}
		if !.IsNone() {
			panic("cannot specify logicaltype for a struct")
		}
		return Must(NewGroupNode(, , , ))
	case reflect.Ptr: // if we encounter a pointer create a node for the type it points to, but mark it as optional
		return (, .Elem(), parquet.Repetitions.Optional, )
	case reflect.Array:
		// arrays are repeated or fixed size
		if  == reflect.TypeOf(parquet.Int96{}) {
			return NewInt96Node(, , )
		}

		if .Elem() == reflect.TypeOf(byte(0)) { // something like [12]byte translates to FixedLenByteArray with length 12
			if  == parquet.Types.Undefined {
				 = parquet.Types.FixedLenByteArray
			}
			if  == 0 { // if there was no type length specified in the tag, use the length of the type.
				 = .Len()
			}
			if !.IsNone() {
				return MustPrimitive(NewPrimitiveNodeLogical(, , , , , ))
			}
			return MustPrimitive(NewPrimitiveNodeConverted(, , , , , , , ))
		}
		fallthrough // if it's not a fixed len byte array type, then just treat it like a slice
	case reflect.Slice:
		// for slices, we default to treating them as lists unless the repetition type is set to REPEATED or they are
		// a bytearray/fixedlenbytearray
		switch {
		case  == parquet.Repetitions.Repeated:
			return (, .Elem(), parquet.Repetitions.Repeated, )
		case  == parquet.Types.FixedLenByteArray ||  == parquet.Types.ByteArray:
			if .Elem() != reflect.TypeOf(byte(0)) {
				panic("slice with physical type ByteArray or FixedLenByteArray must be []byte")
			}
			fallthrough
		case .Elem() == reflect.TypeOf(byte(0)):
			if  == parquet.Types.Undefined {
				 = parquet.Types.ByteArray
			}
			if !.IsNone() {
				return MustPrimitive(NewPrimitiveNodeLogical(, , , , , ))
			}
			return MustPrimitive(NewPrimitiveNodeConverted(, , , , , , , ))
		default:
			var  *taggedInfo
			if  != nil {
				 = &taggedInfo{}
				* = .CopyForValue()
			}

			if !.IsNone() && !.Equals(ListLogicalType{}) {
				panic("slice must either be repeated or a List type")
			}
			if  != ConvertedTypes.None &&  != ConvertedTypes.List {
				panic("slice must either be repeated or a List type")
			}
			return Must(ListOf((, .Elem(), parquet.Repetitions.Required, ), , ))
		}
	case reflect.String:
		// strings are byte arrays or fixedlen byte array
		 := parquet.Types.ByteArray
		switch  {
		case parquet.Types.Undefined, parquet.Types.ByteArray:
		case parquet.Types.FixedLenByteArray:
			 = parquet.Types.FixedLenByteArray
		default:
			panic("string fields should be of type bytearray or fixedlenbytearray only")
		}

		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , , , ))
		}

		return MustPrimitive(NewPrimitiveNodeConverted(, , , , , , , ))
	case reflect.Int, reflect.Int32, reflect.Int8, reflect.Int16, reflect.Int64:
		// handle integer types, default to setting the corresponding logical type
		 := parquet.Types.Int32
		if .Bits() == 64 {
			 = parquet.Types.Int64
		}

		if  != parquet.Types.Undefined {
			 = 
		}

		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , , , ))
		}

		 := int8(.Bits())
		if  != parquet.Types.Undefined {
			switch  {
			case parquet.Types.Int32:
				 = 32
			case parquet.Types.Int64:
				 = 64
			}
		}

		if  != ConvertedTypes.None {
			return MustPrimitive(NewPrimitiveNodeConverted(, , , , 0, , , ))
		}

		return MustPrimitive(NewPrimitiveNodeLogical(, , NewIntLogicalType(, true), , 0, ))
	case reflect.Uint, reflect.Uint32, reflect.Uint8, reflect.Uint16, reflect.Uint64:
		// handle unsigned integer types and default to the corresponding logical type for it.
		 := parquet.Types.Int32
		if .Bits() == 64 {
			 = parquet.Types.Int64
		}

		if  != parquet.Types.Undefined {
			 = 
		}

		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , , , ))
		}

		 := int8(.Bits())
		if  != parquet.Types.Undefined {
			switch  {
			case parquet.Types.Int32:
				 = 32
			case parquet.Types.Int64:
				 = 64
			}
		}

		if  != ConvertedTypes.None {
			return MustPrimitive(NewPrimitiveNodeConverted(, , , , 0, , , ))
		}

		return MustPrimitive(NewPrimitiveNodeLogical(, , NewIntLogicalType(, false), , 0, ))
	case reflect.Bool:
		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , parquet.Types.Boolean, , ))
		}
		return MustPrimitive(NewPrimitiveNodeConverted(, , parquet.Types.Boolean, , , , , ))
	case reflect.Float32:
		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , parquet.Types.Float, , ))
		}
		return MustPrimitive(NewPrimitiveNodeConverted(, , parquet.Types.Float, , , , , ))
	case reflect.Float64:
		if !.IsNone() {
			return MustPrimitive(NewPrimitiveNodeLogical(, , , parquet.Types.Double, , ))
		}
		return MustPrimitive(NewPrimitiveNodeConverted(, , parquet.Types.Double, , , , , ))
	}
	return nil
}

// NewSchemaFromStruct generates a schema from an object type via reflection of
// the type and reading struct tags for "parquet".
//
// # Rules
//
// Everything defaults to Required repetition, unless otherwise specified.
// Pointer types become Optional repetition.
// Arrays and Slices become logical List types unless using the tag `repetition=repeated`.
//
// A length specified byte field (like [5]byte) becomes a fixed_len_byte_array of that length
// unless otherwise specified by tags.
//
// string and []byte both become ByteArray unless otherwise specified.
//
// Integer types will default to having a logical type of the appropriate bit width
// and signedness rather than having no logical type, ie: an int8 will become an int32
// node with logical type Int(bitWidth=8, signed=true).
//
// Structs will become group nodes with the fields of the struct as the fields of the group,
// recursively creating the nodes.
//
// maps will become appropriate Map structures in the schema of the defined key and values.
//
// # Available Tags
//
// name: by default the node will have the same name as the field, this tag let's you specify a name
//
// type: Specify the physical type instead of using the field type
//
// length: specify the type length of the node, only relevant for fixed_len_byte_array
//
// scale: specify the scale for a decimal field
//
// precision: specify the precision for a decimal field
//
// fieldid: specify the field ID for that node, defaults to -1 which means it is not set in the parquet file.
//
// repetition: specify the repetition as something other than what is determined by the type
//
// converted: specify the Converted Type of the field
//
// logical: specify the logical type of the field, if using decimal then the scale and precision
// will be determined by the precision and scale fields, or by the logical.precision / logical.scale fields
// with the logical. prefixed versions taking precedence. For Time or Timestamp logical types,
// use logical.unit=<millis|micros|nanos> and logical.isadjustedutc=<true|false> to set those. Unit is required
// isadjustedutc defaults to true. For Integer logical type, use logical.bitwidth and logical.signed to specify
// those values, with bitwidth being required, and signed defaulting to true.
//
// All tags other than name can use a prefix of "key<tagname>=<value>" to refer to the type of the key for a map
// and "value<tagname>=<value>" to refer to the value type of a map or the element of a list (such as the type of a slice)
func ( interface{}) ( *Schema,  error) {
	 := reflect.TypeOf()
	if .Kind() == reflect.Ptr {
		 = .Elem()
	}

	// typeToNode uses panics to fail fast / fail early instead of propagating
	// errors up recursive stacks. so we recover here and return it as an error
	defer func() {
		if  := recover();  != nil {
			 = nil
			 = utils.FormatRecoveredError("unknown panic", )
		}
	}()

	 := typeToNode(.Name(), , parquet.Repetitions.Repeated, nil)
	return NewSchema(.(*GroupNode)), nil
}

var parquetTypeToReflect = map[parquet.Type]reflect.Type{
	parquet.Types.Boolean:           reflect.TypeOf(true),
	parquet.Types.Int32:             reflect.TypeOf(int32(0)),
	parquet.Types.Int64:             reflect.TypeOf(int64(0)),
	parquet.Types.Float:             reflect.TypeOf(float32(0)),
	parquet.Types.Double:            reflect.TypeOf(float64(0)),
	parquet.Types.Int96:             reflect.TypeOf(parquet.Int96{}),
	parquet.Types.ByteArray:         reflect.TypeOf(parquet.ByteArray{}),
	parquet.Types.FixedLenByteArray: reflect.TypeOf(parquet.FixedLenByteArray{}),
}

func typeFromNode( Node) reflect.Type {
	switch .Type() {
	case Primitive:
		 := parquetTypeToReflect[.(*PrimitiveNode).PhysicalType()]
		// if a bytearray field is annotated as a String logical type or a UTF8 converted type
		// then use a string instead of parquet.ByteArray / parquet.FixedLenByteArray which are []byte
		if .LogicalType().Equals(StringLogicalType{}) || .ConvertedType() == ConvertedTypes.UTF8 {
			 = reflect.TypeOf(string(""))
		}

		if .RepetitionType() == parquet.Repetitions.Optional {
			 = reflect.PointerTo()
		} else if .RepetitionType() == parquet.Repetitions.Repeated {
			 = reflect.SliceOf()
		}

		return 
	case Group:
		 := .(*GroupNode)
		switch .ConvertedType() {
		case ConvertedTypes.List:
			// According to the Parquet Spec, a list should always be a 3-level structure
			//
			//	<list-repetition> group <name> (LIST) {
			//		repeated group list {
			//			<element-repetition> <element-type> element;
			//		}
			//	}
			//
			// Outer-most level must be a group annotated with LIST containing a single field named "list".
			// this level must be only optional (if the list is nullable) or required
			// Middle level, named list, must be repeated group with a single field named "element"
			// "element" field is the lists element type and repetition, which should be only required or optional

			if .fields.Len() != 1 {
				panic("invalid list node, should have exactly 1 child.")
			}

			if .fields[0].RepetitionType() != parquet.Repetitions.Repeated {
				panic("invalid list node, child should be repeated")
			}

			// it is required that the repeated group of elements is named "list" and it's element
			// field is named "element", however existing data may not use this so readers shouldn't
			// enforce them as errors
			//
			// Rules for backward compatibility from the parquet spec:
			//
			// 1) if the repeated field is not a group, then it's type is the element type and elements
			//    must be required.
			// 2) if the repeated field is a group with multiple fields, then its type is the element type
			//    and elements must be required.
			// 3) if the repeated field is a group with one field AND is named either "array" or uses the
			//    LIST-annotated group's name with "_tuple" suffix, then the repeated type is the element
			//    type and the elements must be required.
			// 4) otherwise, the repeated field's type is the element type with the repeated field's repetition

			 := false
			 := false
			var  reflect.Type
			 := .fields[0]
			switch {
			case .Type() == Primitive,
				.(*GroupNode).fields.Len() > 1,
				.(*GroupNode).fields.Len() == 1 && (.Name() == "array" || .Name() == .Name()+"_tuple"):
				 = true
				 = ()
			default:
				 = true
				 = (.(*GroupNode).fields[0])
			}

			if  && .Kind() == reflect.Ptr {
				 = .Elem()
			}
			if  {
				 = reflect.SliceOf()
			}
			if .RepetitionType() == parquet.Repetitions.Optional {
				 = reflect.PointerTo()
			}
			return 
		case ConvertedTypes.Map, ConvertedTypes.MapKeyValue:
			// According to the Parquet Spec, the outer-most level should be
			// a group containing a single field named "key_value" with repetition
			// either optional or required for whether or not the map is nullable.
			//
			// The key_value middle level *must* be a repeated group with a "key" field
			// and *optionally* a "value" field
			//
			// the "key" field *must* be required and must always exist
			//
			// the "value" field can be required or optional or omitted.
			//
			// 	<map-repetition> group <name> (MAP) {
			//		repeated group key_value {
			//			required <key-type> key;
			//			<value-repetition> <value-type> value;
			//		}
			//	}

			if .fields.Len() != 1 {
				panic("invalid map node, should have exactly 1 child")
			}

			if .fields[0].Type() != Group {
				panic("invalid map node, child should be a group node")
			}

			// that said, this may not be used in existing data and should not be
			// enforced as errors when reading.
			//
			// some data may also incorrectly use MAP_KEY_VALUE instead of MAP
			//
			// so any group with MAP_KEY_VALUE that is not contained inside of a "MAP"
			// group, should be considered equivalent to being a MAP group itself.
			//
			// in addition, the fields may not be called "key" and "value" in existing
			// data, and as such should not be enforced as errors when reading.

			 := .fields[0].(*GroupNode)

			 := .FieldIndexByName("key")
			if  == -1 {
				 = 0 // use first child if there is no child named "key"
			}

			 := (.fields[])
			if .Kind() == reflect.Ptr {
				 = .Elem()
			}
			// can't use a []byte as a key for a map, so use string
			if  == reflect.TypeOf(parquet.ByteArray{}) ||  == reflect.TypeOf(parquet.FixedLenByteArray{}) {
				 = reflect.TypeOf(string(""))
			}

			// if the value node is omitted, then consider this a "set" and make it a
			// map[key-type]bool
			 := reflect.TypeOf(true)
			if .fields.Len() > 1 {
				 := .FieldIndexByName("value")
				if  == -1 {
					 = 1 // use second child if there is no child named "value"
				}

				 = (.fields[])
			}

			 := reflect.MapOf(, )
			if .RepetitionType() == parquet.Repetitions.Optional {
				 = reflect.PointerTo()
			}
			return 
		default:
			 := []reflect.StructField{}
			for ,  := range .fields {
				 = append(, reflect.StructField{
					Name:    .Name(),
					Type:    (),
					PkgPath: "parquet",
				})
			}

			 := reflect.StructOf()
			if .RepetitionType() == parquet.Repetitions.Repeated {
				return reflect.SliceOf()
			}
			if .RepetitionType() == parquet.Repetitions.Optional {
				return reflect.PointerTo()
			}
			return 
		}
	}
	panic("what happened?")
}

// NewStructFromSchema generates a struct type as a reflect.Type from the schema
// by using the appropriate physical types and making things either pointers or slices
// based on whether they are repeated/optional/required. It does not use the logical
// or converted types to change the physical storage so that it is more efficient to use
// the resulting type for reading without having to do conversions.
//
// It will use maps for map types and slices for list types, but otherwise ignores the
// converted and logical types of the nodes. Group nodes that are not List or Map will
// be nested structs.
func ( *Schema) ( reflect.Type,  error) {
	defer func() {
		if  := recover();  != nil {
			 = nil
			 = utils.FormatRecoveredError("unknown panic", )
		}
	}()

	 = typeFromNode(.root)
	if .Kind() == reflect.Slice || .Kind() == reflect.Ptr {
		return .Elem(), nil
	}
	return
}