github.com/apache/arrow/go/v14@v14.0.1/parquet/internal/encoding/fixed_len_byte_array_decoder.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one 2 // or more contributor license agreements. See the NOTICE file 3 // distributed with this work for additional information 4 // regarding copyright ownership. The ASF licenses this file 5 // to you under the Apache License, Version 2.0 (the 6 // "License"); you may not use this file except in compliance 7 // with the License. You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package encoding 18 19 import ( 20 "math" 21 22 "github.com/apache/arrow/go/v14/internal/utils" 23 "github.com/apache/arrow/go/v14/parquet" 24 "golang.org/x/xerrors" 25 ) 26 27 // PlainFixedLenByteArrayDecoder is a plain encoding decoder for Fixed Length Byte Arrays 28 type PlainFixedLenByteArrayDecoder struct { 29 decoder 30 } 31 32 // Type returns the physical type this decoder operates on, FixedLength Byte Arrays 33 func (PlainFixedLenByteArrayDecoder) Type() parquet.Type { 34 return parquet.Types.FixedLenByteArray 35 } 36 37 // Decode populates out with fixed length byte array values until either there are no more 38 // values to decode or the length of out has been filled. Then returns the total number of values 39 // that were decoded. 40 func (pflba *PlainFixedLenByteArrayDecoder) Decode(out []parquet.FixedLenByteArray) (int, error) { 41 max := utils.MinInt(len(out), pflba.nvals) 42 numBytesNeeded := max * pflba.typeLen 43 if numBytesNeeded > len(pflba.data) || numBytesNeeded > math.MaxInt32 { 44 return 0, xerrors.New("parquet: eof exception") 45 } 46 47 for idx := range out[:max] { 48 out[idx] = pflba.data[:pflba.typeLen] 49 pflba.data = pflba.data[pflba.typeLen:] 50 } 51 return max, nil 52 } 53 54 // DecodeSpaced does the same as Decode but spaces out the resulting slice according to the bitmap leaving space for null values 55 func (pflba *PlainFixedLenByteArrayDecoder) DecodeSpaced(out []parquet.FixedLenByteArray, nullCount int, validBits []byte, validBitsOffset int64) (int, error) { 56 toRead := len(out) - nullCount 57 valuesRead, err := pflba.Decode(out[:toRead]) 58 if err != nil { 59 return valuesRead, err 60 } 61 if valuesRead != toRead { 62 return valuesRead, xerrors.New("parquet: number of values / definitions levels read did not match") 63 } 64 65 return spacedExpand(out, nullCount, validBits, validBitsOffset), nil 66 }