zeroshade commented on a change in pull request #11146: URL: https://github.com/apache/arrow/pull/11146#discussion_r725197612
########## File path: go/parquet/file/column_reader.go ########## @@ -0,0 +1,542 @@ +// 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 file + +import ( + "github.com/apache/arrow/go/arrow/bitutil" + "github.com/apache/arrow/go/arrow/memory" + "github.com/apache/arrow/go/parquet" + "github.com/apache/arrow/go/parquet/internal/encoding" + "github.com/apache/arrow/go/parquet/internal/encryption" + format "github.com/apache/arrow/go/parquet/internal/gen-go/parquet" + "github.com/apache/arrow/go/parquet/internal/utils" + "github.com/apache/arrow/go/parquet/schema" + "golang.org/x/xerrors" +) + +const ( + // 4 MB is the default maximum page header size + defaultMaxPageHeaderSize = 4 * 1024 * 1024 + // 16 KB is the default expected page header size + defaultPageHeaderSize = 16 * 1024 +) + +//go:generate go run ../../arrow/_tools/tmpl/main.go -i -data=../internal/encoding/physical_types.tmpldata column_reader_types.gen.go.tmpl + +func isDictIndexEncoding(e format.Encoding) bool { + return e == format.Encoding_RLE_DICTIONARY || e == format.Encoding_PLAIN_DICTIONARY +} + +func colHasSpacedValues(c *schema.Column) bool { + if c.MaxRepetitionLevel() > 0 { + // repeated + flat case + return c.SchemaNode().RepetitionType() != parquet.Repetitions.Required + } + + // non-repeated+nested case + // find if a node forces nulls in the lowest level along the hierarchy + n := c.SchemaNode() + for n != nil { + if n.RepetitionType() == parquet.Repetitions.Optional { + return true + } + n = n.Parent() + } + return false +} + +// CryptoContext is a context for keeping track of the current methods for decrypting. +// It keeps track of the row group and column numbers along with references to the +// decryptor objects. +type CryptoContext struct { + StartDecryptWithDictionaryPage bool + RowGroupOrdinal int16 + ColumnOrdinal int16 + MetaDecryptor encryption.Decryptor + DataDecryptor encryption.Decryptor +} + +// ColumnReader is the basic interface for all column readers. +// +// To actually Read out the column data, you need to convert to the properly +// typed ColumnReader type such as *BooleanColumnReader etc. +type ColumnReader interface { + // HasNext returns whether there is more data to be read in this column + // and row group. + HasNext() bool + // Type returns the underlying physical type of the column + Type() parquet.Type + // Descriptor returns the column schema container + Descriptor() *schema.Column + // if HasNext returns false because of an error, this will return the error + // it encountered. Otherwise this will be nil if it's just the end of the + // column + Err() error + // Skip buffered values + consumeBufferedValues(int64) + // number of available values left + numAvail() int64 + // read the definition levels and return the number of definitions, + // and the number of values to be read (number of def levels == maxdef level) + // it also populates the passed in slice which should be sized appropriately. + readDefinitionLevels(levels []int16) (int, int64) + // read the repetition levels and return the number of repetition levels read + // also populates the passed in slice, which should be sized appropriately. + readRepetitionLevels(levels []int16) int + // get the current page reader + pager() PageReader + // set a page reader into the columnreader so it can be reused. + setPageReader(PageReader) +} + +type columnReader struct { + descr *schema.Column + rdr PageReader + repetitionDecoder encoding.LevelDecoder + definitionDecoder encoding.LevelDecoder + + curPage Page + curEncoding format.Encoding + curDecoder encoding.TypedDecoder + + // number of currently buffered values in the current page + numBuffered int64 + // the number of values we've decoded so far + numDecoded int64 + // will be true if we have read in a new dictionary page Review comment: So i just realized, while i copied this over from the C++ impl, i never actually use it because of the way I shifted some things around compared to the C++ implementation. So i'm just gonna remove the `newDict` var -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
