zeroshade commented on a change in pull request #11146:
URL: https://github.com/apache/arrow/pull/11146#discussion_r725195667



##########
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
+       newDict bool
+       mem     memory.Allocator
+
+       decoders      map[format.Encoding]encoding.TypedDecoder
+       decoderTraits encoding.DecoderTraits
+
+       // is set when an error is encountered
+       err          error
+       defLvlBuffer []int16

Review comment:
       This exists because you need the definition levels in order to know how 
many values to read in, but repetition levels are purely an output. Since a 
consumer can pass a nil slice for both i didn't want to allocate a new slice 
for every read if they were passing nil for the definition levels so this 
buffer is an optimization to be used to read in the definition levels if the 
consumer passed null because they didn't care. 
   
   for `repLvls` if they passed nil, we don't care and can just not bother 
reading them in.




-- 
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]


Reply via email to