aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/blevesearch/zapx/v14/zap.md
blob: d74dc548b80f1b5153e3946fee00ee33e3809734 (plain)
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# ZAP File Format 

## Legend

### Sections

    |========|
    |        | section
    |========|
    
### Fixed-size fields

    |--------|        |----|        |--|        |-|
    |        | uint64 |    | uint32 |  | uint16 | | uint8
    |--------|        |----|        |--|        |-|

### Varints

    |~~~~~~~~|
    |        | varint(up to uint64)
    |~~~~~~~~|

### Arbitrary-length fields

    |--------...---|
    |              | arbitrary-length field (string, vellum, roaring bitmap)
    |--------...---|

### Chunked data

	[--------]
	[        ]
	[--------]

## Overview

Footer section describes the configuration of particular ZAP file. The format of footer is version-dependent, so it is necessary to check `V` field before the parsing.

            |==================================================|
            | Stored Fields                                    |
            |==================================================|
    |-----> | Stored Fields Index                              |
    |       |==================================================|   
    |       | Dictionaries + Postings + DocValues              | 
    |       |==================================================|
    | |---> | DocValues Index                                  |
    | |     |==================================================|   
    | |     | Fields                                           |
    | |     |==================================================|
    | | |-> | Fields Index                                     |
    | | |   |========|========|========|========|====|====|====|
    | | |   |     D# |     SF |      F |    FDV | CF |  V | CC | (Footer)
    | | |   |========|====|===|====|===|====|===|====|====|====|
    | | |                 |        |        |
    |-+-+-----------------|        |        |
      | |--------------------------|        |
      |-------------------------------------|

     D#. Number of Docs.
     SF. Stored Fields Index Offset.
      F. Field Index Offset.
    FDV. Field DocValue Offset.
     CF. Chunk Factor.
      V. Version.
     CC. CRC32.

## Stored Fields

Stored Fields Index is `D#` consecutive 64-bit unsigned integers - offsets, where relevant Stored Fields Data records are located.

    0                                [SF]                   [SF + D# * 8]
    | Stored Fields                  | Stored Fields Index              |
    |================================|==================================|
    |                                |                                  |
    |       |--------------------|   ||--------|--------|. . .|--------||
    |   |-> | Stored Fields Data |   ||      0 |      1 |     | D# - 1 ||
    |   |   |--------------------|   ||--------|----|---|. . .|--------||
    |   |                            |              |                   |
    |===|============================|==============|===================|
        |                                           |
        |-------------------------------------------|

Stored Fields Data is an arbitrary size record, which consists of metadata and [Snappy](https://github.com/golang/snappy)-compressed data.

    Stored Fields Data
    |~~~~~~~~|~~~~~~~~|~~~~~~~~...~~~~~~~~|~~~~~~~~...~~~~~~~~|
    |    MDS |    CDS |                MD |                CD |
    |~~~~~~~~|~~~~~~~~|~~~~~~~~...~~~~~~~~|~~~~~~~~...~~~~~~~~|
    
    MDS. Metadata size.
    CDS. Compressed data size.
    MD. Metadata.
    CD. Snappy-compressed data.

## Fields

Fields Index section located between addresses `F` and `len(file) - len(footer)` and consist of `uint64` values (`F1`, `F2`, ...) which are offsets to records in Fields section. We have `F# = (len(file) - len(footer) - F) / sizeof(uint64)` fields.


    (...)                            [F]                       [F + F#]
    | Fields                         | Fields Index.                  |
    |================================|================================|
    |                                |                                |
    |   |~~~~~~~~|~~~~~~~~|---...---|||--------|--------|...|--------||
    ||->|   Dict | Length |    Name |||      0 |      1 |   | F# - 1 ||
    ||  |~~~~~~~~|~~~~~~~~|---...---|||--------|----|---|...|--------||
    ||                               |              |                 |
    ||===============================|==============|=================|
     |                                              |
     |----------------------------------------------|
        

## Dictionaries + Postings

Each of fields has its own dictionary, encoded in [Vellum](https://github.com/couchbase/vellum) format. Dictionary consists of pairs `(term, offset)`, where `offset` indicates the position of postings (list of documents) for this particular term.

	|================================================================|- Dictionaries + 
	|                                                                |   Postings +
	|                                                                |    DocValues
	|    Freq/Norm (chunked)                                         |
	|    [~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]                      |
	| |->[ Freq | Norm (float32 under varint) ]                      |
	| |  [~~~~~~|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~]                      |
	| |                                                              |
	| |------------------------------------------------------------| |
	|    Location Details (chunked)                                | |
	|    [~~~~~~|~~~~~|~~~~~~~|~~~~~|~~~~~~|~~~~~~~~|~~~~~]        | |
	| |->[ Size | Pos | Start | End | Arr# | ArrPos | ... ]        | |
	| |  [~~~~~~|~~~~~|~~~~~~~|~~~~~|~~~~~~|~~~~~~~~|~~~~~]        | |
	| |                                                            | |
	| |----------------------|                                     | |
	|          Postings List |                                     | |
	|         |~~~~~~~~|~~~~~|~~|~~~~~~~~|-----------...--|        | |
	|      |->|    F/N |     LD | Length | ROARING BITMAP |        | |
	|      |  |~~~~~|~~|~~~~~~~~|~~~~~~~~|-----------...--|        | |
	|      |        |----------------------------------------------| |
	|      |--------------------------------------|                  |
	|          Dictionary                         |                  |
	|         |~~~~~~~~|--------------------------|-...-|            |
	|      |->| Length | VELLUM DATA : (TERM -> OFFSET) |            |
	|      |  |~~~~~~~~|----------------------------...-|            |
	|      |                                                         |
	|======|=========================================================|- DocValues Index
	|      |                                                         |
	|======|=========================================================|- Fields
	|      |                                                         |
	| |~~~~|~~~|~~~~~~~~|---...---|                                  |
	| |   Dict | Length |    Name |                                  |
	| |~~~~~~~~|~~~~~~~~|---...---|                                  |
	|                                                                |
	|================================================================|

## DocValues

DocValues Index is `F#` pairs of varints, one pair per field. Each pair of varints indicates start and end point of DocValues slice.

	|================================================================|
	|     |------...--|                                              |
	|  |->| DocValues |<-|                                           |
	|  |  |------...--|  |                                           |
	|==|=================|===========================================|- DocValues Index
	||~|~~~~~~~~~|~~~~~~~|~~|           |~~~~~~~~~~~~~~|~~~~~~~~~~~~||
	|| DV1 START | DV1 STOP | . . . . . | DV(F#) START | DV(F#) END ||
	||~~~~~~~~~~~|~~~~~~~~~~|           |~~~~~~~~~~~~~~|~~~~~~~~~~~~||
	|================================================================|

DocValues is chunked Snappy-compressed values for each document and field.

    [~~~~~~~~~~~~~~~|~~~~~~|~~~~~~~~~|-...-|~~~~~~|~~~~~~~~~|--------------------...-]
    [ Doc# in Chunk | Doc1 | Offset1 | ... | DocN | OffsetN | SNAPPY COMPRESSED DATA ]
    [~~~~~~~~~~~~~~~|~~~~~~|~~~~~~~~~|-...-|~~~~~~|~~~~~~~~~|--------------------...-]

Last 16 bytes are description of chunks.

    |~~~~~~~~~~~~...~|----------------|----------------|
    |   Chunk Sizes  | Chunk Size Arr |         Chunk# |
    |~~~~~~~~~~~~...~|----------------|----------------|