-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindexSchema.go
129 lines (108 loc) · 2.4 KB
/
indexSchema.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import "io"
type AttrEngine_e uint32
const (
DEFAULT = AttrEngine_e(iota)
ROWWISE
COLUMNAR
)
type AttrFlags_e uint32
const (
ATTR_NONE = 0
ATTR_COLUMNAR = 1
ATTR_COLUMNAR_HASHES = 2
)
type FieldFlags_e uint32
const (
FIELD_NONE = 0
FIELD_STORED = 1
FIELD_INDEXED = 2
FIELD_IS_ATTRIBUTE = 4
)
type columnInfo struct {
Name string
Etype uint32
CompatRowItem uint32
Bitoffset, Bitcount int32
FieldFlags FieldFlags_e
AttrFlags AttrFlags_e
AttrEngine AttrEngine_e
Payload bool
}
func readField(rd io.Reader, uVersion uint32) columnInfo {
var c columnInfo
if uVersion >= 57 {
c.Name = getString(rd)
c.Etype = getDword(rd)
c.Payload = getByteBool(rd)
} else {
c = readCol(rd, uVersion)
}
if uVersion < 59 {
c.FieldFlags |= FIELD_INDEXED
}
return c
}
func (c *columnInfo) saveField(w io.Writer) {
saveString(w, c.Name)
saveDword(w, c.Etype)
saveBoolByte(w, c.Payload)
}
func readCol(rd io.Reader, uVersion uint32) columnInfo {
var c columnInfo
c.Name = getString(rd)
if c.Name == "" {
c.Name = "@emptyname"
}
c.Etype = getDword(rd)
c.CompatRowItem = getDword(rd)
c.Bitoffset = getInt32(rd)
c.Bitcount = getInt32(rd)
c.Payload = getByteBool(rd)
if uVersion >= 61 {
c.AttrFlags = AttrFlags_e(getDword(rd))
}
if uVersion >= 63 {
c.AttrEngine = AttrEngine_e(getDword(rd))
}
return c
}
func (c *columnInfo) saveCol(w io.Writer, uVersion uint32) {
saveString(w, c.Name)
saveDword(w, c.Etype)
saveDword(w, c.CompatRowItem)
saveInt(w, int(c.Bitoffset))
saveInt(w, int(c.Bitcount))
saveBoolByte(w, c.Payload)
if uVersion >= 61 {
saveDword(w, uint32(c.AttrFlags))
}
if uVersion >= 63 {
saveDword(w, uint32(c.AttrEngine))
}
}
type indexschema struct {
Fields, Attrs []columnInfo
}
func (c *indexschema) load(rd io.Reader, uVersion uint32) {
nfields := int(getDword(rd))
for i := 0; i < nfields; i++ {
c.Fields = append(c.Fields, readField(rd, uVersion))
}
nattrs := int(getDword(rd))
for i := 0; i < nattrs; i++ {
c.Attrs = append(c.Attrs, readCol(rd, uVersion))
}
}
func (c *indexschema) save(w io.Writer, uVersion uint32) {
nfields := len(c.Fields)
saveInt(w, nfields)
for i := 0; i < nfields; i++ {
c.Fields[i].saveField(w)
}
nattrs := len(c.Attrs)
saveInt(w, nattrs)
for i := 0; i < nattrs; i++ {
c.Attrs[i].saveCol(w, uVersion)
}
}