-
Notifications
You must be signed in to change notification settings - Fork 0
/
shard.go
69 lines (60 loc) · 1.05 KB
/
shard.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
package cof
import (
"bytes"
"encoding/binary"
"fmt"
"io"
)
type Shard struct {
columns map[string]Column
columnsOffsets []ColOffset
}
type BlockHeader struct {
Min int64
Max int64
Rows int64
Size int64
}
type Field struct {
Name string
Type string
}
type ColOffset struct {
Name string
Offset int64
}
func newShard(id string) *Shard {
return &Shard{
columns: map[string]Column{},
columnsOffsets: []ColOffset{},
}
}
func (s *Shard) AddColumn(name string, col Column) {
s.columns[name] = col
}
func (s *Shard) Flush(w io.Writer) error {
// @TODO(KL): write block metadata and simple indexes
buffer := new(bytes.Buffer)
for name, col := range s.columns {
written, err := col.WriteTo(buffer)
if err != nil {
return err
}
fmt.Println(name, written)
s.columnsOffsets = append(s.columnsOffsets, ColOffset{
Name: name,
Offset: written,
})
}
block := BlockHeader{
Min: 0,
Max: 0,
Rows: 0,
Size: 0,
}
err := binary.Write(w, binary.LittleEndian, block)
if err != nil {
return err
}
return nil
}