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

     1  package parquet
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  )
     7  
     8  var (
     9  	// ErrCorrupted is an error returned by the Err method of ColumnPages
    10  	// instances when they encountered a mismatch between the CRC checksum
    11  	// recorded in a page header and the one computed while reading the page
    12  	// data.
    13  	ErrCorrupted = errors.New("corrupted parquet page")
    14  
    15  	// ErrMissingRootColumn is an error returned when opening an invalid parquet
    16  	// file which does not have a root column.
    17  	ErrMissingRootColumn = errors.New("parquet file is missing a root column")
    18  
    19  	// ErrRowGroupSchemaMissing is an error returned when attempting to write a
    20  	// row group but the source has no schema.
    21  	ErrRowGroupSchemaMissing = errors.New("cannot write rows to a row group which has no schema")
    22  
    23  	// ErrRowGroupSchemaMismatch is an error returned when attempting to write a
    24  	// row group but the source and destination schemas differ.
    25  	ErrRowGroupSchemaMismatch = errors.New("cannot write row groups with mismatching schemas")
    26  
    27  	// ErrRowGroupSortingColumnsMismatch is an error returned when attempting to
    28  	// write a row group but the sorting columns differ in the source and
    29  	// destination.
    30  	ErrRowGroupSortingColumnsMismatch = errors.New("cannot write row groups with mismatching sorting columns")
    31  
    32  	// ErrSeekOutOfRange is an error returned when seeking to a row index which
    33  	// is less than the first row of a page.
    34  	ErrSeekOutOfRange = errors.New("seek to row index out of page range")
    35  
    36  	// ErrUnexpectedDictionaryPage is an error returned when a page reader
    37  	// encounters a dictionary page after the first page, or in a column
    38  	// which does not use a dictionary encoding.
    39  	ErrUnexpectedDictionaryPage = errors.New("unexpected dictionary page")
    40  
    41  	// ErrMissingPageHeader is an error returned when a page reader encounters
    42  	// a malformed page header which is missing page-type-specific information.
    43  	ErrMissingPageHeader = errors.New("missing page header")
    44  
    45  	// ErrUnexpectedRepetitionLevels is an error returned when attempting to
    46  	// decode repetition levels into a page which is not part of a repeated
    47  	// column.
    48  	ErrUnexpectedRepetitionLevels = errors.New("unexpected repetition levels")
    49  
    50  	// ErrUnexpectedDefinitionLevels is an error returned when attempting to
    51  	// decode definition levels into a page which is part of a required column.
    52  	ErrUnexpectedDefinitionLevels = errors.New("unexpected definition levels")
    53  
    54  	// ErrTooManyRowGroups is returned when attempting to generate a parquet
    55  	// file with more than MaxRowGroups row groups.
    56  	ErrTooManyRowGroups = errors.New("the limit of 32767 row groups has been reached")
    57  
    58  	// ErrConversion is used to indicate that a conversion betwen two values
    59  	// cannot be done because there are no rules to translate between their
    60  	// physical types.
    61  	ErrInvalidConversion = errors.New("invalid conversion between parquet values")
    62  )
    63  
    64  type errno int
    65  
    66  const (
    67  	ok errno = iota
    68  	indexOutOfBounds
    69  )
    70  
    71  func (e errno) check() {
    72  	switch e {
    73  	case ok:
    74  	case indexOutOfBounds:
    75  		panic("index out of bounds")
    76  	default:
    77  		panic("BUG: unknown error code")
    78  	}
    79  }
    80  
    81  func errRowIndexOutOfBounds(rowIndex, rowCount int64) error {
    82  	return fmt.Errorf("row index out of bounds: %d/%d", rowIndex, rowCount)
    83  }