...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package encoding
18
19 import (
20 "math"
21
22 "github.com/apache/arrow/go/v15/internal/utils"
23 "github.com/apache/arrow/go/v15/parquet"
24 "golang.org/x/xerrors"
25 )
26
27
28 type PlainFixedLenByteArrayDecoder struct {
29 decoder
30 }
31
32
33 func (PlainFixedLenByteArrayDecoder) Type() parquet.Type {
34 return parquet.Types.FixedLenByteArray
35 }
36
37
38
39
40 func (pflba *PlainFixedLenByteArrayDecoder) Decode(out []parquet.FixedLenByteArray) (int, error) {
41 max := utils.Min(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
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 }
67
View as plain text