// 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 parquet

import (
	
	

	
	
	
	format 
)

// Constants for default property values used for the default reader, writer and column props.
const (
	// Default Buffer size used for the Reader
	DefaultBufSize int64 = 4096 * 4
	// Default data page size limit is 1M, it's not guaranteed, but we will try to
	// cut data pages off at this size where possible.
	DefaultDataPageSize int64 = 1024 * 1024
	// Default is for dictionary encoding to be turned on, use WithDictionaryDefault
	// writer property to change that.
	DefaultDictionaryEnabled = true
	// If the dictionary reaches the size of this limitation, the writer will use
	// the fallback encoding (usually plain) instead of continuing to build the
	// dictionary index.
	DefaultDictionaryPageSizeLimit = DefaultDataPageSize
	// In order to attempt to facilitate data page size limits for writing,
	// data is written in batches. Increasing the batch size may improve performance
	// but the larger the batch size, the easier it is to overshoot the datapage limit.
	DefaultWriteBatchSize int64 = 1024
	// Default maximum number of rows for a single row group
	DefaultMaxRowGroupLen int64 = 64 * 1024 * 1024
	// Default is to have stats enabled for all columns, use writer properties to
	// change the default, or to enable/disable for specific columns.
	DefaultStatsEnabled = true
	// If the stats are larger than 4K the writer will skip writing them out anyways.
	DefaultMaxStatsSize int64 = 4096
	// Default is to not write page indexes for columns
	DefaultPageIndexEnabled = false
	DefaultCreatedBy        = "parquet-go version " + arrow.PkgVersion
	DefaultRootName         = "schema"

	DefaultMaxBloomFilterBytes        = 1024 * 1024
	DefaultBloomFilterEnabled         = false
	DefaultBloomFilterFPP             = 0.01
	DefaultAdaptiveBloomFilterEnabled = false
	DefaultBloomFilterCandidates      = 5

	// DefaultALPEnabled is false because ALP is a preview encoding.
	DefaultALPEnabled = false
	// DefaultALPVectorSize is how many values an ALP vector holds unless
	// WithALPVectorSize says otherwise.
	DefaultALPVectorSize = 1024

	minALPVectorSize = 1 << 3
	maxALPVectorSize = 1 << 15

	minimumBloomFilterBytes = 32
	maximumBloomFilterBytes = 128 * 1024 * 1024
)

// ColumnProperties defines the encoding, codec, and so on for a given column.
type ColumnProperties struct {
	Encoding          Encoding
	Codec             compress.Compression
	DictionaryEnabled bool
	// DictionaryCostFallback overrides the codec-based default of the
	// pre-first-page cost-based dictionary fallback; nil keeps the default
	// (enabled only for columns written without page compression). See
	// WithDictionaryCostFallbackFor.
	DictionaryCostFallback     *bool
	StatsEnabled               bool
	PageIndexEnabled           bool
	MaxStatsSize               int64
	CompressionLevel           int
	BloomFilterEnabled         bool
	BloomFilterFPP             float64
	AdaptiveBloomFilterEnabled bool
	BloomFilterCandidates      int
	BloomFilterNDV             int64
	// ALPEnabled permits this column to use the preview ALP encoding.
	ALPEnabled bool
	// ALPVectorSize is how many values each ALP vector of this column holds.
	ALPVectorSize int
}

// DefaultColumnProperties returns the default properties which get utilized for writing.
//
// The default column properties are the following constants:
//
// Encoding:                   Encodings.Plain
// Codec:                      compress.Codecs.Uncompressed
// DictionaryEnabled:	       DefaultDictionaryEnabled
// StatsEnabled:               DefaultStatsEnabled
// PageIndexEnabled:           DefaultPageIndexEnabled
// MaxStatsSize:               DefaultMaxStatsSize
// CompressionLevel:           compress.DefaultCompressionLevel
// BloomFilterEnabled:         DefaultBloomFilterEnabled
// BloomFilterFPP:             DefaultBloomFilterFPP
// AdaptiveBloomFilterEnabled: DefaultAdaptiveBloomFilterEnabled
// BloomFilterCandidates:      DefaultBloomFilterCandidates
func () ColumnProperties {
	return ColumnProperties{
		Encoding:                   Encodings.Plain,
		Codec:                      compress.Codecs.Uncompressed,
		DictionaryEnabled:          DefaultDictionaryEnabled,
		StatsEnabled:               DefaultStatsEnabled,
		PageIndexEnabled:           DefaultPageIndexEnabled,
		MaxStatsSize:               DefaultMaxStatsSize,
		CompressionLevel:           compress.DefaultCompressionLevel,
		BloomFilterEnabled:         DefaultBloomFilterEnabled,
		BloomFilterFPP:             DefaultBloomFilterFPP,
		AdaptiveBloomFilterEnabled: DefaultAdaptiveBloomFilterEnabled,
		BloomFilterCandidates:      DefaultBloomFilterCandidates,
		ALPEnabled:                 DefaultALPEnabled,
		ALPVectorSize:              DefaultALPVectorSize,
	}
}

// SortingColumn specifies a sort order within a rowgroup of a specific leaf column.
type SortingColumn = format.SortingColumn

type writerPropConfig struct {
	wr                         *WriterProperties
	encodings                  map[string]Encoding
	codecs                     map[string]compress.Compression
	compressLevel              map[string]int
	dictEnabled                map[string]bool
	dictCostFallback           map[string]bool
	statsEnabled               map[string]bool
	indexEnabled               map[string]bool
	bloomFilterNDVs            map[string]int64
	bloomFilterFPPs            map[string]float64
	bloomFilterEnabled         map[string]bool
	adaptiveBloomFilterEnabled map[string]bool
	numBloomFilterCandidates   map[string]int
	alpEnabled                 map[string]bool
	alpVectorSize              map[string]int
}

// WriterProperty is used as the options for building a writer properties instance
type WriterProperty func(*writerPropConfig)

// WithAllocator specifies the writer to use the given allocator
func ( memory.Allocator) WriterProperty {
	return func( *writerPropConfig) {
		.wr.mem = 
	}
}

// WithDictionaryDefault sets the default value for whether to enable dictionary encoding
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.DictionaryEnabled = 
	}
}

// WithDictionaryFor allows enabling or disabling dictionary encoding for a given column path string
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.dictEnabled[] = 
	}
}

// WithDictionaryPath is like WithDictionaryFor, but takes a ColumnPath type
func ( ColumnPath,  bool) WriterProperty {
	return WithDictionaryFor(.String(), )
}

// WithDictionaryPageSizeLimit is the limit of the dictionary at which the writer
// will fallback to plain encoding instead
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.dictPagesize = 
	}
}

// WithDictionaryCostFallbackFor controls the cost-based dictionary fallback for the
// given column path: before the first data page of a column chunk is cut, the writer
// discards the dictionary and falls back to the plain encoding when the dictionary
// plus the encoded indices are not smaller than the raw values (mirroring
// parquet-mr's shouldFallBack). That comparison is done on uncompressed sizes, so by
// default it only runs for columns written without page compression — for columns
// with a codec configured the dictionary is kept, since near-incompressible
// dictionary indices routinely beat plain pages that compress well. This option
// overrides the codec-based default in either direction: false keeps an explicitly
// requested dictionary for an uncompressed column, true forces the check for a
// compressed one. The DictionaryPageSizeLimit fallback always stays in effect.
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.dictCostFallback[] = 
	}
}

// WithDictionaryCostFallbackPath is like WithDictionaryCostFallbackFor, but takes
// a ColumnPath type.
func ( ColumnPath,  bool) WriterProperty {
	return WithDictionaryCostFallbackFor(.String(), )
}

// WithBatchSize specifies the number of rows to use for batch writes to columns
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.batchSize = 
	}
}

// WithMaxRowGroupLength specifies the number of rows as the maximum number of rows for a given row group in the writer.
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.maxRowGroupLen = 
	}
}

// WithDataPageSize specifies the size to use for splitting data pages for column writing.
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.pageSize = 
	}
}

// WithDataPageVersion specifies whether to use Version 1 or Version 2 of the DataPage spec
func ( DataPageVersion) WriterProperty {
	return func( *writerPropConfig) {
		.wr.dataPageVersion = 
	}
}

// WithVersion specifies which Parquet Spec version to utilize for writing.
func ( Version) WriterProperty {
	return func( *writerPropConfig) {
		.wr.parquetVersion = 
	}
}

// WithCreatedBy specifies the "created by" string to use for the writer
func ( string) WriterProperty {
	return func( *writerPropConfig) {
		.wr.createdBy = 
	}
}

// WithRootName enables customization of the name used for the root schema node. This is required
// to maintain compatibility with other tools.
func ( string) WriterProperty {
	return func( *writerPropConfig) {
		.wr.rootName = 
	}
}

// WithRootRepetition enables customization of the repetition used for the root schema node.
// This is required to maintain compatibility with other tools.
func ( Repetition) WriterProperty {
	return func( *writerPropConfig) {
		.wr.rootRepetition = 
	}
}

// WithEncoding defines the encoding that is used when we aren't using dictionary encoding.
//
// This is either applied if dictionary encoding is disabled, or if we fallback if the dictionary
// grew too large.
func ( Encoding) WriterProperty {
	return func( *writerPropConfig) {
		if  == Encodings.PlainDict ||  == Encodings.RLEDict {
			panic("parquet: can't use dictionary encoding as fallback encoding")
		}
		.wr.defColumnProps.Encoding = 
	}
}

// WithEncodingFor is for defining the encoding only for a specific column path. This encoding will be used
// if dictionary encoding is disabled for the column or if we fallback because the dictionary grew too large
func ( string,  Encoding) WriterProperty {
	return func( *writerPropConfig) {
		if  == Encodings.PlainDict ||  == Encodings.RLEDict {
			panic("parquet: can't use dictionary encoding as fallback encoding")
		}
		.encodings[] = 
	}
}

// WithEncodingPath is the same as WithEncodingFor but takes a ColumnPath directly.
func ( ColumnPath,  Encoding) WriterProperty {
	return WithEncodingFor(.String(), )
}

// WithALPEncoding permits all columns to use the preview ALP encoding. Readers
// without ALP support cannot read files that use it, so ALP is disabled by
// default.
//
// The option grants permission rather than selecting ALP. A column still asks for
// the encoding through WithEncodingFor or WithEncodingPath, and asking for it
// without this option panics, as asking for any unusable encoding does.
//
// ALP supports only FLOAT and DOUBLE columns. WithEncoding(Encodings.ALP) sets
// it for every column, so writing any other column without a dictionary
// (BOOLEAN and INT96 never use one) panics; prefer selecting it per column.
//
// A column reaches ALP only with dictionary encoding turned off. A dictionary
// takes precedence over the encoding a column asks for, and a writer that drops
// the dictionary falls back to PLAIN rather than to ALP, so pair the request with
// WithDictionaryDefault(false) or WithDictionaryFor(path, false).
//
// WithALPEncodingFor overrides this setting for one column.
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.ALPEnabled = 
	}
}

// WithALPEncodingFor permits or rejects ALP for one column. See WithALPEncoding
// for the requirements that apply when ALP is enabled.
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.alpEnabled[] = 
	}
}

// WithALPEncodingPath is the same as WithALPEncodingFor but takes a ColumnPath.
func ( ColumnPath,  bool) WriterProperty {
	return WithALPEncodingFor(.String(), )
}

// WithALPVectorSize sets how many values each ALP vector holds for all
// columns. It must be a power of two from 8 to 32768; the default is
// DefaultALPVectorSize. Larger vectors amortize the per-vector header, while
// smaller ones let each vector pick the scaling that suits its values.
//
// It only affects columns written with the ALP encoding, and readers honor
// whatever size a page declares.
func ( int) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.ALPVectorSize = 
	}
}

// WithALPVectorSizeFor sets the ALP vector size for one column. See
// WithALPVectorSize.
func ( string,  int) WriterProperty {
	return func( *writerPropConfig) {
		.alpVectorSize[] = 
	}
}

// WithALPVectorSizePath is the same as WithALPVectorSizeFor but takes a
// ColumnPath.
func ( ColumnPath,  int) WriterProperty {
	return WithALPVectorSizeFor(.String(), )
}

// WithCompression specifies the default compression type to use for column writing.
func ( compress.Compression) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.Codec = 
	}
}

// WithCompressionFor specifies the compression type for the given column.
func ( string,  compress.Compression) WriterProperty {
	return func( *writerPropConfig) {
		.codecs[] = 
	}
}

// WithCompressionPath is the same as WithCompressionFor but takes a ColumnPath directly.
func ( ColumnPath,  compress.Compression) WriterProperty {
	return WithCompressionFor(.String(), )
}

// WithMaxStatsSize sets a maximum size for the statistics before we decide not to include them.
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.MaxStatsSize = 
	}
}

// WithCompressionLevel specifies the default compression level for the compressor in every column.
//
// The provided compression level is compressor specific. The user would have to know what the available
// levels are for the selected compressor. If the compressor does not allow for selecting different
// compression levels, then this function will have no effect. Parquet and Arrow will not validate the
// passed compression level. If no level is selected by the user or if the special compress.DefaultCompressionLevel
// value is used, then parquet will select the compression level.
func ( int) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.CompressionLevel = 
	}
}

// WithCompressionLevelFor is like WithCompressionLevel but only for the given column path.
func ( string,  int) WriterProperty {
	return func( *writerPropConfig) {
		.compressLevel[] = 
	}
}

// WithCompressionLevelPath is the same as WithCompressionLevelFor but takes a ColumnPath
func ( ColumnPath,  int) WriterProperty {
	return WithCompressionLevelFor(.String(), )
}

// WithStats specifies a default for whether or not to enable column statistics.
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.StatsEnabled = 
	}
}

// WithStatsFor specifies a per column value as to enable or disable statistics in the resulting file.
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.statsEnabled[] = 
	}
}

// WithStatsPath is the same as WithStatsFor but takes a ColumnPath
func ( ColumnPath,  bool) WriterProperty {
	return WithStatsFor(.String(), )
}

// WithEncryptionProperties specifies the file level encryption handling for writing the file.
func ( *FileEncryptionProperties) WriterProperty {
	return func( *writerPropConfig) {
		.wr.encryptionProps = 
	}
}

// WithStoreDecimalAsInteger specifies whether to try using an int32/int64 for storing
// decimal data rather than fixed len byte arrays if the precision is low enough.
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.storeDecimalAsInt = 
	}
}

// WithSortingColumns allow specifying the sorting columns in the written metadata.
// If this is set, the user should ensure that records are sorted by these columns,
// otherwise the sorting data will be inconsistent with the sorting_columns metadata.
func ( []SortingColumn) WriterProperty {
	return func( *writerPropConfig) {
		.wr.sortingCols = 
	}
}

// WithPageIndexEnabled specifies the default value for whether or not to write page indexes for columns
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.PageIndexEnabled = 
	}
}

// WithPageIndexEnabled specifies a per column value as to enable or disable writing page indexes for the column
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.indexEnabled[] = 
	}
}

// WithPageIndexEnabledPath is like WithPageIndexEnabledFor, but takes a ColumnPath
func ( ColumnPath,  bool) WriterProperty {
	return WithPageIndexEnabledFor(.String(), )
}

// WithMaxBloomFilterBytes sets the maximum size for a bloom filter, after which
// it is abandoned and not written to the file.
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		if  < minimumBloomFilterBytes ||  > maximumBloomFilterBytes {
			panic("parquet: maximum bloom filter size must be between 32 bytes and 128 MiB")
		}
		.wr.maxBloomFilterBytes = 
	}
}

// WithBloomFilterEnabled sets the default value for whether to enable writing bloom
// filters for columns. This is the default value for all columns, but can be overridden
// by using WithBloomFilterEnabledFor or WithBloomFilterEnabledPath.
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.BloomFilterEnabled = 
	}
}

// WithBloomFilterEnabledFor specifies a per column value as to enable or disable writing
// bloom filters for the column.
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.bloomFilterEnabled[] = 
	}
}

// WithBloomFilterEnabledPath is like WithBloomFilterEnabledFor, but takes a ColumnPath
func ( ColumnPath,  bool) WriterProperty {
	return WithBloomFilterEnabledFor(.String(), )
}

// WithBloomFilterFPP sets the default value for the false positive probability for writing
// bloom filters.
func ( float64) WriterProperty {
	return func( *writerPropConfig) {
		validateBloomFilterFPP()
		.wr.defColumnProps.BloomFilterFPP = 
	}
}

// WithBloomFilterFPPFor specifies a per column value for the false positive probability
// for writing bloom filters.
func ( string,  float64) WriterProperty {
	return func( *writerPropConfig) {
		validateBloomFilterFPP()
		.bloomFilterFPPs[] = 
	}
}

func validateBloomFilterFPP( float64) {
	if  <= 0 ||  >= 1 || math.IsNaN() {
		panic("parquet: bloom filter false-positive probability must be in (0, 1)")
	}
}

// WithBloomFilterFPPPath is like WithBloomFilterFPPFor, but takes a ColumnPath
func ( ColumnPath,  float64) WriterProperty {
	return WithBloomFilterFPPFor(.String(), )
}

// WithAdaptiveBloomFilterEnabled sets the default value for whether to enable writing
// adaptive bloom filters for columns. This is the default value for all columns,
// but can be overridden by using WithAdaptiveBloomFilterEnabledFor or
// WithAdaptiveBloomFilterEnabledPath.
//
// Using an Adaptive Bloom filter will attempt to use multiple candidate bloom filters
// when building the column, with different expected distinct values. It will attempt
// to use the smallest candidate bloom filter that achieves the desired false positive
// probability. Dropping candidates bloom filters that are no longer viable.
func ( bool) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.AdaptiveBloomFilterEnabled = 
	}
}

// WithAdaptiveBloomFilterEnabledFor specifies a per column value as to enable or disable writing
// adaptive bloom filters for the column.
func ( string,  bool) WriterProperty {
	return func( *writerPropConfig) {
		.adaptiveBloomFilterEnabled[] = 
	}
}

// WithAdaptiveBloomFilterEnabledPath is like WithAdaptiveBloomFilterEnabledFor, but takes a ColumnPath
func ( ColumnPath,  bool) WriterProperty {
	return WithAdaptiveBloomFilterEnabledFor(.String(), )
}

// WithBloomFilterCandidates sets the number of candidate bloom filters to use when building
// an adaptive bloom filter.
func ( int) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.BloomFilterCandidates = 
	}
}

// WithBloomFilterCandidatesFor specifies a per column value for the number of candidate
// bloom filters to use when building an adaptive bloom filter.
func ( string,  int) WriterProperty {
	return func( *writerPropConfig) {
		.numBloomFilterCandidates[] = 
	}
}

// WithBloomFilterCandidatesPath is like WithBloomFilterCandidatesFor, but takes a ColumnPath
func ( ColumnPath,  int) WriterProperty {
	return WithBloomFilterCandidatesFor(.String(), )
}

// WithBloomFilterNDV sets the default value for the expected number of distinct values
// to be written for the column. This is ignored when using adaptive bloom filters.
func ( int64) WriterProperty {
	return func( *writerPropConfig) {
		.wr.defColumnProps.BloomFilterNDV = 
	}
}

// WithBloomFilterNDVFor specifies a per column value for the expected number of distinct values
// to be written for the column. This is ignored when using adaptive bloom filters.
func ( string,  int64) WriterProperty {
	return func( *writerPropConfig) {
		.bloomFilterNDVs[] = 
	}
}

// WithBloomFilterNDVPath is like WithBloomFilterNDVFor, but takes a ColumnPath
func ( ColumnPath,  int64) WriterProperty {
	return WithBloomFilterNDVFor(.String(), )
}

// WriterProperties is the collection of properties to use for writing a parquet file. The values are
// read only once it has been constructed.
type WriterProperties struct {
	mem                 memory.Allocator
	dictPagesize        int64
	batchSize           int64
	maxRowGroupLen      int64
	pageSize            int64
	parquetVersion      Version
	createdBy           string
	dataPageVersion     DataPageVersion
	rootName            string
	rootRepetition      Repetition
	storeDecimalAsInt   bool
	maxBloomFilterBytes int64

	defColumnProps  ColumnProperties
	columnProps     map[string]*ColumnProperties
	encryptionProps *FileEncryptionProperties
	sortingCols     []SortingColumn
}

func defaultWriterProperties() *WriterProperties {
	return &WriterProperties{
		mem:                 memory.DefaultAllocator,
		dictPagesize:        DefaultDictionaryPageSizeLimit,
		batchSize:           DefaultWriteBatchSize,
		maxRowGroupLen:      DefaultMaxRowGroupLen,
		pageSize:            DefaultDataPageSize,
		parquetVersion:      V2_LATEST,
		dataPageVersion:     DataPageV1,
		createdBy:           DefaultCreatedBy,
		rootName:            DefaultRootName,
		rootRepetition:      Repetitions.Repeated,
		maxBloomFilterBytes: DefaultMaxBloomFilterBytes,
		defColumnProps:      DefaultColumnProperties(),
		sortingCols:         []SortingColumn{},
	}
}

// NewWriterProperties takes a list of options for building the properties. If multiple options are used which conflict
// then the last option is the one which will take effect. If no WriterProperty options are provided, then the default
// properties will be utilized for writing.
//
// The Default properties use the following constants:
//
//	Allocator:          memory.DefaultAllocator
//	DictionaryPageSize: DefaultDictionaryPageSizeLimit
//	BatchSize:          DefaultWriteBatchSize
//	MaxRowGroupLength:  DefaultMaxRowGroupLen
//	PageSize:           DefaultDataPageSize
//	ParquetVersion:     V2_LATEST
//	DataPageVersion:    DataPageV1
//	CreatedBy:          DefaultCreatedBy
func ( ...WriterProperty) *WriterProperties {
	 := writerPropConfig{
		wr:                         defaultWriterProperties(),
		encodings:                  make(map[string]Encoding),
		codecs:                     make(map[string]compress.Compression),
		compressLevel:              make(map[string]int),
		dictEnabled:                make(map[string]bool),
		dictCostFallback:           make(map[string]bool),
		statsEnabled:               make(map[string]bool),
		indexEnabled:               make(map[string]bool),
		bloomFilterNDVs:            make(map[string]int64),
		bloomFilterFPPs:            make(map[string]float64),
		bloomFilterEnabled:         make(map[string]bool),
		adaptiveBloomFilterEnabled: make(map[string]bool),
		numBloomFilterCandidates:   make(map[string]int),
		alpEnabled:                 make(map[string]bool),
		alpVectorSize:              make(map[string]int),
	}
	for ,  := range  {
		(&)
	}

	.wr.columnProps = make(map[string]*ColumnProperties)
	 := func( string) *ColumnProperties {
		if ,  := .wr.columnProps[];  {
			return 
		}
		.wr.columnProps[] = new(ColumnProperties)
		*.wr.columnProps[] = .wr.defColumnProps
		return .wr.columnProps[]
	}

	for ,  := range .encodings {
		().Encoding = 
	}

	for ,  := range .codecs {
		().Codec = 
	}

	for ,  := range .compressLevel {
		().CompressionLevel = 
	}

	for ,  := range .dictEnabled {
		().DictionaryEnabled = 
	}

	for ,  := range .dictCostFallback {
		().DictionaryCostFallback = &
	}

	for ,  := range .statsEnabled {
		().StatsEnabled = 
	}

	for ,  := range .indexEnabled {
		().PageIndexEnabled = 
	}

	for ,  := range .bloomFilterEnabled {
		().BloomFilterEnabled = 
	}

	for ,  := range .bloomFilterFPPs {
		().BloomFilterFPP = 
	}

	for ,  := range .bloomFilterNDVs {
		().BloomFilterNDV = 
	}

	for ,  := range .adaptiveBloomFilterEnabled {
		().AdaptiveBloomFilterEnabled = 
	}

	for ,  := range .numBloomFilterCandidates {
		().BloomFilterCandidates = 
	}

	for ,  := range .alpEnabled {
		().ALPEnabled = 
	}
	for ,  := range .alpVectorSize {
		().ALPVectorSize = 
	}

	// The check runs here rather than in the options, because an option that
	// selects ALP may be given before the one that allows it.
	if .wr.defColumnProps.Encoding == Encodings.ALP && !.wr.defColumnProps.ALPEnabled {
		panic("parquet: ALP encoding requires WithALPEncoding(true)")
	}
	checkALPVectorSize("", .wr.defColumnProps.ALPVectorSize)
	for ,  := range .wr.columnProps {
		if .Encoding == Encodings.ALP && !.ALPEnabled {
			panic(fmt.Sprintf("parquet: ALP encoding for column %q requires WithALPEncoding(true) or WithALPEncodingFor(%q, true)",
				, ))
		}
		checkALPVectorSize(, .ALPVectorSize)
	}

	return .wr
}

// ALPEncodingEnabled reports whether columns may use the ALP encoding by
// default. Use ALPEncodingEnabledFor for a specific column.
func ( *WriterProperties) () bool { return .defColumnProps.ALPEnabled }

// ALPVectorSize returns the default number of values in each ALP vector. Use
// ALPVectorSizeFor for a specific column.
func ( *WriterProperties) () int { return .defColumnProps.ALPVectorSize }

// ALPEncodingEnabledFor reports whether the given column may be written with the
// ALP encoding, or the default value if the column was not separately specified.
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .ALPEnabled
	}
	return .defColumnProps.ALPEnabled
}

// ALPEncodingEnabledPath is the same as ALPEncodingEnabledFor but takes a
// ColumnPath object.
func ( *WriterProperties) ( ColumnPath) bool {
	return .ALPEncodingEnabledFor(.String())
}

// ALPVectorSizeFor returns how many values each ALP vector of the given column
// holds, or the default if the column was not separately specified.
func ( *WriterProperties) ( string) int {
	if ,  := .columnProps[];  {
		return .ALPVectorSize
	}
	return .defColumnProps.ALPVectorSize
}

// ALPVectorSizePath is the same as ALPVectorSizeFor but takes a ColumnPath
// object.
func ( *WriterProperties) ( ColumnPath) int {
	return .ALPVectorSizeFor(.String())
}

func checkALPVectorSize( string,  int) {
	if  >= minALPVectorSize &&  <= maxALPVectorSize && &(-1) == 0 {
		return
	}
	 := "the ALP vector size"
	if  != "" {
		 += fmt.Sprintf(" of column %q", )
	}
	panic(fmt.Sprintf("parquet: %s must be a power of two from %d to %d, got %d",
		, minALPVectorSize, maxALPVectorSize, ))
}

// FileEncryptionProperties returns the current encryption properties that were
// used to create the writer properties.
func ( *WriterProperties) () *FileEncryptionProperties {
	return .encryptionProps
}

func ( *WriterProperties) () memory.Allocator    { return .mem }
func ( *WriterProperties) () string              { return .createdBy }
func ( *WriterProperties) () string               { return .rootName }
func ( *WriterProperties) () Repetition     { return .rootRepetition }
func ( *WriterProperties) () int64          { return .batchSize }
func ( *WriterProperties) () int64            { return .pageSize }
func ( *WriterProperties) () int64 { return .dictPagesize }

func ( *WriterProperties) () Version                 { return .parquetVersion }
func ( *WriterProperties) () DataPageVersion { return .dataPageVersion }
func ( *WriterProperties) () int64         { return .maxRowGroupLen }
func ( *WriterProperties) () []SortingColumn  { return .sortingCols }

// Compression returns the default compression type that will be used for any columns that don't
// have a specific compression defined.
func ( *WriterProperties) () compress.Compression { return .defColumnProps.Codec }

// CompressionFor will return the compression type that is specified for the given column path, or
// the default compression codec if there isn't one specific to this column.
func ( *WriterProperties) ( string) compress.Compression {
	if ,  := .columnProps[];  {
		return .Codec
	}
	return .defColumnProps.Codec
}

// CompressionPath is the same as CompressionFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) compress.Compression {
	return .CompressionFor(.String())
}

// CompressionLevel returns the default compression level that will be used for any column
// that doesn't have a compression level specified for it.
func ( *WriterProperties) () int { return .defColumnProps.CompressionLevel }

// CompressionLevelFor returns the compression level that will be utilized for the given column,
// or the default compression level if the column doesn't have a specific level specified.
func ( *WriterProperties) ( string) int {
	if ,  := .columnProps[];  {
		return .CompressionLevel
	}
	return .defColumnProps.CompressionLevel
}

// CompressionLevelPath is the same as CompressionLevelFor but takes a ColumnPath object
func ( *WriterProperties) ( ColumnPath) int {
	return .CompressionLevelFor(.String())
}

// Encoding returns the default encoding that will be utilized for any columns which don't have a different value
// specified.
func ( *WriterProperties) () Encoding { return .defColumnProps.Encoding }

// EncodingFor returns the encoding that will be used for the given column path, or the default encoding if there
// isn't one specified for this column.
func ( *WriterProperties) ( string) Encoding {
	if ,  := .columnProps[];  {
		return .Encoding
	}
	return .defColumnProps.Encoding
}

// EncodingPath is the same as EncodingFor but takes a ColumnPath object
func ( *WriterProperties) ( ColumnPath) Encoding {
	return .EncodingFor(.String())
}

// DictionaryIndexEncoding returns which encoding will be used for the Dictionary Index values based on the
// parquet version. V1 uses PlainDict and V2 uses RLEDict
func ( *WriterProperties) () Encoding {
	if .parquetVersion == V1_0 {
		return Encodings.PlainDict
	}
	return Encodings.RLEDict
}

// DictionaryPageEncoding returns the encoding that will be utilized for the DictionaryPage itself based on the parquet
// version. V1 uses PlainDict, v2 uses Plain
func ( *WriterProperties) () Encoding {
	if .parquetVersion == V1_0 {
		return Encodings.PlainDict
	}
	return Encodings.Plain
}

// DictionaryEnabled returns the default value as for whether or not dictionary encoding will be utilized for columns
// that aren't separately specified.
func ( *WriterProperties) () bool { return .defColumnProps.DictionaryEnabled }

// DictionaryEnabledFor returns whether or not dictionary encoding will be used for the specified column when writing
// or the default value if the column was not separately specified.
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .DictionaryEnabled
	}
	return .defColumnProps.DictionaryEnabled
}

// DictionaryCostFallbackEnabledFor returns whether the pre-first-page cost-based
// dictionary fallback applies for the given column path: an explicit per-column
// WithDictionaryCostFallbackFor setting wins, otherwise the fallback is enabled
// only when the column is written without page compression, since the cost
// comparison is done on uncompressed sizes.
func ( *WriterProperties) ( string) bool {
	,  := .columnProps[]
	if ! {
		return .defColumnProps.Codec == compress.Codecs.Uncompressed
	}
	if .DictionaryCostFallback != nil {
		return *.DictionaryCostFallback
	}
	return .Codec == compress.Codecs.Uncompressed
}

// DictionaryEnabledPath is the same as DictionaryEnabledFor but takes a ColumnPath object.
func ( *WriterProperties) ( ColumnPath) bool {
	return .DictionaryEnabledFor(.String())
}

// StatisticsEnabled returns the default value for whether or not stats are enabled to be written for columns
// that aren't separately specified.
func ( *WriterProperties) () bool { return .defColumnProps.StatsEnabled }

// StatisticsEnabledFor returns whether stats will be written for the given column path, or the default value if
// it wasn't separately specified.
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .StatsEnabled
	}
	return .defColumnProps.StatsEnabled
}

// StatisticsEnabledPath is the same as StatisticsEnabledFor but takes a ColumnPath object.
func ( *WriterProperties) ( ColumnPath) bool {
	return .StatisticsEnabledFor(.String())
}

// PageIndexEnabled returns the default value for whether or not page indexes will be written
func ( *WriterProperties) () bool { return .defColumnProps.PageIndexEnabled }

// PageIndexEnabledFor returns whether page index writing is enabled for the given column path, or
// the default value if it wasn't specified separately.
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .PageIndexEnabled
	}
	return .defColumnProps.PageIndexEnabled
}

// PageIndexEnabledPath is the same as PageIndexEnabledFor but takes a ColumnPath object
func ( *WriterProperties) ( ColumnPath) bool {
	return .PageIndexEnabledFor(.String())
}

// MaxStatsSize returns the default maximum size for stats
func ( *WriterProperties) () int64 { return .defColumnProps.MaxStatsSize }

// MaxStatsSizeFor returns the maximum stat size for the given column path
func ( *WriterProperties) ( string) int64 {
	if ,  := .columnProps[];  {
		return .MaxStatsSize
	}
	return .defColumnProps.MaxStatsSize
}

// MaxStatsSizePath is the same as MaxStatsSizeFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) int64 {
	return .MaxStatsSizeFor(.String())
}

// ColumnEncryptionProperties returns the specific properties for encryption that will be used for the given column path
func ( *WriterProperties) ( string) *ColumnEncryptionProperties {
	if .encryptionProps != nil {
		return .encryptionProps.ColumnEncryptionProperties()
	}
	return nil
}

// StoreDecimalAsInteger returns the config option controlling whether or not
// to try storing decimal data as an integer type if the precision is low enough
// (1 <= prec <= 18 can be stored as an int), otherwise it will be stored as
// a fixed len byte array.
func ( *WriterProperties) () bool {
	return .storeDecimalAsInt
}

// MaxBloomFilterBytes returns the maximum number of bytes that a bloom filter can use
func ( *WriterProperties) () int64 {
	return .maxBloomFilterBytes
}

// BloomFilterEnabled returns the default value for whether or not bloom filters are enabled
func ( *WriterProperties) () bool {
	return .defColumnProps.BloomFilterEnabled
}

// BloomFilterEnabledFor returns whether or not bloom filters are enabled for the given column path
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .BloomFilterEnabled
	}
	return .defColumnProps.BloomFilterEnabled
}

// BloomFilterEnabledPath is the same as BloomFilterEnabledFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) bool {
	return .BloomFilterEnabledFor(.String())
}

// BloomFilterFPP returns the default false positive probability for bloom filters
func ( *WriterProperties) () float64 {
	return .defColumnProps.BloomFilterFPP
}

// BloomFilterFPPFor returns the false positive probability for the given column path
func ( *WriterProperties) ( string) float64 {
	if ,  := .columnProps[];  {
		return .BloomFilterFPP
	}
	return .defColumnProps.BloomFilterFPP
}

// BloomFilterFPPPath is the same as BloomFilterFPPFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) float64 {
	return .BloomFilterFPPFor(.String())
}

// AdaptiveBloomFilterEnabled returns the default value for whether or not adaptive bloom filters are enabled
func ( *WriterProperties) () bool {
	return .defColumnProps.AdaptiveBloomFilterEnabled
}

// AdaptiveBloomFilterEnabledFor returns whether or not adaptive bloom filters are enabled for the given column path
func ( *WriterProperties) ( string) bool {
	if ,  := .columnProps[];  {
		return .AdaptiveBloomFilterEnabled
	}
	return .defColumnProps.AdaptiveBloomFilterEnabled
}

// AdaptiveBloomFilterEnabledPath is the same as AdaptiveBloomFilterEnabledFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) bool {
	return .AdaptiveBloomFilterEnabledFor(.String())
}

// BloomFilterCandidates returns the default number of candidates to use for bloom filters
func ( *WriterProperties) () int {
	return .defColumnProps.BloomFilterCandidates
}

// BloomFilterCandidatesFor returns the number of candidates to use for the given column path
func ( *WriterProperties) ( string) int {
	if ,  := .columnProps[];  {
		return .BloomFilterCandidates
	}
	return .defColumnProps.BloomFilterCandidates
}

// BloomFilterCandidatesPath is the same as BloomFilterCandidatesFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) int {
	return .BloomFilterCandidatesFor(.String())
}

// BloomFilterNDV returns the default number of distinct values to use for bloom filters
func ( *WriterProperties) () int64 {
	return .defColumnProps.BloomFilterNDV
}

// BloomFilterNDVFor returns the number of distinct values to use for the given column path
func ( *WriterProperties) ( string) int64 {
	if ,  := .columnProps[];  {
		return .BloomFilterNDV
	}
	return .defColumnProps.BloomFilterNDV
}

// BloomFilterNDVPath is the same as BloomFilterNDVFor but takes a ColumnPath
func ( *WriterProperties) ( ColumnPath) int64 {
	return .BloomFilterNDVFor(.String())
}