github.com/fraugster/parquet-go@v0.12.0/type_int64.go (about) 1 package goparquet 2 3 import ( 4 "encoding/binary" 5 "fmt" 6 "io" 7 8 "github.com/fraugster/parquet-go/parquet" 9 ) 10 11 type int64PlainDecoder struct { 12 r io.Reader 13 } 14 15 func (i *int64PlainDecoder) init(r io.Reader) error { 16 i.r = r 17 18 return nil 19 } 20 21 func (i *int64PlainDecoder) decodeValues(dst []interface{}) (int, error) { 22 var d int64 23 24 for idx := range dst { 25 if err := binary.Read(i.r, binary.LittleEndian, &d); err != nil { 26 return idx, err 27 } 28 dst[idx] = d 29 } 30 return len(dst), nil 31 } 32 33 type int64PlainEncoder struct { 34 w io.Writer 35 } 36 37 func (i *int64PlainEncoder) Close() error { 38 return nil 39 } 40 41 func (i *int64PlainEncoder) init(w io.Writer) error { 42 i.w = w 43 44 return nil 45 } 46 47 func (i *int64PlainEncoder) encodeValues(values []interface{}) error { 48 d := make([]int64, len(values)) 49 for i := range values { 50 d[i] = values[i].(int64) 51 } 52 return binary.Write(i.w, binary.LittleEndian, d) 53 } 54 55 type int64DeltaBPDecoder struct { 56 deltaBitPackDecoder64 57 } 58 59 func (d *int64DeltaBPDecoder) decodeValues(dst []interface{}) (int, error) { 60 for i := range dst { 61 u, err := d.next() 62 if err != nil { 63 return i, err 64 } 65 dst[i] = u 66 } 67 68 return len(dst), nil 69 } 70 71 type int64DeltaBPEncoder struct { 72 deltaBitPackEncoder64 73 } 74 75 func (d *int64DeltaBPEncoder) encodeValues(values []interface{}) error { 76 for i := range values { 77 if err := d.addInt64(values[i].(int64)); err != nil { 78 return err 79 } 80 } 81 82 return nil 83 } 84 85 type int64Store struct { 86 repTyp parquet.FieldRepetitionType 87 88 stats *int64Stats 89 pageStats *int64Stats 90 91 *ColumnParameters 92 } 93 94 func (is *int64Store) getStats() minMaxValues { 95 return is.stats 96 } 97 98 func (is *int64Store) getPageStats() minMaxValues { 99 return is.pageStats 100 } 101 102 func (is *int64Store) params() *ColumnParameters { 103 if is.ColumnParameters == nil { 104 panic("ColumnParameters is nil") 105 } 106 return is.ColumnParameters 107 } 108 109 func (*int64Store) sizeOf(v interface{}) int { 110 if vv, ok := v.([]int64); ok { 111 return 8 * len(vv) 112 } 113 return 8 114 } 115 116 func (is *int64Store) parquetType() parquet.Type { 117 return parquet.Type_INT64 118 } 119 120 func (is *int64Store) repetitionType() parquet.FieldRepetitionType { 121 return is.repTyp 122 } 123 124 func (is *int64Store) reset(rep parquet.FieldRepetitionType) { 125 is.repTyp = rep 126 is.stats.reset() 127 is.pageStats.reset() 128 } 129 130 func (is *int64Store) setMinMax(j int64) { 131 is.stats.setMinMax(j) 132 is.pageStats.setMinMax(j) 133 } 134 135 func (is *int64Store) getValues(v interface{}) ([]interface{}, error) { 136 var vals []interface{} 137 switch typed := v.(type) { 138 case int64: 139 is.setMinMax(typed) 140 vals = []interface{}{typed} 141 case []int64: 142 if is.repTyp != parquet.FieldRepetitionType_REPEATED { 143 return nil, fmt.Errorf("the value is not repeated but it is an array") 144 } 145 vals = make([]interface{}, len(typed)) 146 for j := range typed { 147 is.setMinMax(typed[j]) 148 vals[j] = typed[j] 149 } 150 default: 151 return nil, fmt.Errorf("unsupported type for storing in int64 column: %T => %+v", v, v) 152 } 153 154 return vals, nil 155 } 156 157 func (*int64Store) append(arrayIn interface{}, value interface{}) interface{} { 158 if arrayIn == nil { 159 arrayIn = make([]int64, 0, 1) 160 } 161 return append(arrayIn.([]int64), value.(int64)) 162 }