github.com/segmentio/parquet-go@v0.0.0-20230712180008-5d42db8f0d47/limits.go (about)

     1  package parquet
     2  
     3  import (
     4  	"fmt"
     5  	"math"
     6  )
     7  
     8  const (
     9  	// MaxColumnDepth is the maximum column depth supported by this package.
    10  	MaxColumnDepth = math.MaxInt8
    11  
    12  	// MaxColumnIndex is the maximum column index supported by this package.
    13  	MaxColumnIndex = math.MaxInt16
    14  
    15  	// MaxRepetitionLevel is the maximum repetition level supported by this
    16  	// package.
    17  	MaxRepetitionLevel = math.MaxUint8
    18  
    19  	// MaxDefinitionLevel is the maximum definition level supported by this
    20  	// package.
    21  	MaxDefinitionLevel = math.MaxUint8
    22  
    23  	// MaxRowGroups is the maximum number of row groups which can be contained
    24  	// in a single parquet file.
    25  	//
    26  	// This limit is enforced by the use of 16 bits signed integers in the file
    27  	// metadata footer of parquet files. It is part of the parquet specification
    28  	// and therefore cannot be changed.
    29  	MaxRowGroups = math.MaxInt16
    30  )
    31  
    32  const (
    33  	estimatedSizeOfByteArrayValues = 20
    34  )
    35  
    36  func makeRepetitionLevel(i int) byte {
    37  	checkIndexRange("repetition level", i, 0, MaxRepetitionLevel)
    38  	return byte(i)
    39  }
    40  
    41  func makeDefinitionLevel(i int) byte {
    42  	checkIndexRange("definition level", i, 0, MaxDefinitionLevel)
    43  	return byte(i)
    44  }
    45  
    46  func makeColumnIndex(i int) int16 {
    47  	checkIndexRange("column index", i, 0, MaxColumnIndex)
    48  	return int16(i)
    49  }
    50  
    51  func makeNumValues(i int) int32 {
    52  	checkIndexRange("number of values", i, 0, math.MaxInt32)
    53  	return int32(i)
    54  }
    55  
    56  func checkIndexRange(typ string, i, min, max int) {
    57  	if i < min || i > max {
    58  		panic(errIndexOutOfRange(typ, i, min, max))
    59  	}
    60  }
    61  
    62  func errIndexOutOfRange(typ string, i, min, max int) error {
    63  	return fmt.Errorf("%s out of range: %d not in [%d:%d]", typ, i, min, max)
    64  }