-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathstreamname.go
104 lines (85 loc) · 1.8 KB
/
streamname.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package orc
import (
"fmt"
"io"
"github.com/scritchley/orc/proto"
)
type streamMap map[streamName]io.Reader
func (s streamMap) reset() {
for k := range s {
delete(s, k)
}
}
func (s streamMap) set(name streamName, buf io.Reader) {
s[name] = buf
}
func (s streamMap) get(name streamName) io.Reader {
if b, ok := s[name]; ok {
return b
}
return nil
}
type streamName struct {
columnID int
kind proto.Stream_Kind
}
func (s streamName) String() string {
return fmt.Sprintf("col:%v kind:%s", s.columnID, s.kind)
}
type streamWriterMap map[streamName]*BufferedWriter
func (s streamWriterMap) reset() {
for k := range s {
delete(s, k)
}
}
func (s streamWriterMap) create(codec CompressionCodec, name streamName) *BufferedWriter {
stream := NewBufferedWriter(codec)
s[name] = stream
return stream
}
func (s streamWriterMap) size() int64 {
var total int64
for i := range s {
total += int64(s[i].Len())
}
return total
}
// Stream is an individual stream for the TreeWriter.
type Stream struct {
kind *proto.Stream_Kind
buffer *BufferedWriter
}
func (s Stream) Positions() []uint64 {
return s.buffer.Positions()
}
type writerMap map[int]TreeWriter
func (w writerMap) forEach(fn func(i int, t TreeWriter) error) error {
for i := 0; i < len(w); i++ {
if t, ok := w[i]; ok {
err := fn(i, t)
if err != nil {
return err
}
}
}
return nil
}
func (w writerMap) size() int64 {
var size int
for _, treeWriter := range w {
for _, stream := range treeWriter.Streams() {
size += stream.buffer.Len()
}
}
return int64(size)
}
func (w writerMap) add(id int, t TreeWriter) {
w[id] = t
}
func (w writerMap) encodings() []*proto.ColumnEncoding {
encodings := make([]*proto.ColumnEncoding, len(w))
for i := range encodings {
encodings[i] = w[i].Encoding()
}
return encodings
}