forked from segmentio/parquet-go
/
offset_index.go
63 lines (47 loc) · 2.08 KB
/
offset_index.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
package parquet
import (
"github.com/segmentio/parquet-go/format"
)
type OffsetIndex interface {
// NumPages returns the number of pages in the offset index.
NumPages() int
// Offset returns the offset starting from the beginning of the file for the
// page at the given index.
Offset(int) int64
// CompressedPageSize returns the size of the page at the given index
// (in bytes).
CompressedPageSize(int) int64
// FirstRowIndex returns the the first row in the page at the given index.
//
// The returned row index is based on the row group that the page belongs
// to, the first row has index zero.
FirstRowIndex(int) int64
}
type emptyOffsetIndex struct{}
func (emptyOffsetIndex) NumPages() int { return 0 }
func (emptyOffsetIndex) Offset(int) int64 { return 0 }
func (emptyOffsetIndex) CompressedPageSize(int) int64 { return 0 }
func (emptyOffsetIndex) FirstRowIndex(int) int64 { return 0 }
type fileOffsetIndex format.OffsetIndex
func (i *fileOffsetIndex) NumPages() int {
return len(i.PageLocations)
}
func (i *fileOffsetIndex) Offset(j int) int64 {
return i.PageLocations[j].Offset
}
func (i *fileOffsetIndex) CompressedPageSize(j int) int64 {
return int64(i.PageLocations[j].CompressedPageSize)
}
func (i *fileOffsetIndex) FirstRowIndex(j int) int64 {
return i.PageLocations[j].FirstRowIndex
}
type byteArrayOffsetIndex struct{ page *byteArrayPage }
func (i byteArrayOffsetIndex) NumPages() int { return 1 }
func (i byteArrayOffsetIndex) Offset(int) int64 { return 0 }
func (i byteArrayOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() }
func (i byteArrayOffsetIndex) FirstRowIndex(int) int64 { return 0 }
type fixedLenByteArrayOffsetIndex struct{ page *fixedLenByteArrayPage }
func (i fixedLenByteArrayOffsetIndex) NumPages() int { return 1 }
func (i fixedLenByteArrayOffsetIndex) Offset(int) int64 { return 0 }
func (i fixedLenByteArrayOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() }
func (i fixedLenByteArrayOffsetIndex) FirstRowIndex(int) int64 { return 0 }