github.com/vc42/parquet-go@v0.0.0-20240320194221-1a9adb5f23f5/offset_index.go (about) 1 package parquet 2 3 import ( 4 "github.com/vc42/parquet-go/format" 5 ) 6 7 type OffsetIndex interface { 8 // NumPages returns the number of pages in the offset index. 9 NumPages() int 10 11 // Offset returns the offset starting from the beginning of the file for the 12 // page at the given index. 13 Offset(int) int64 14 15 // CompressedPageSize returns the size of the page at the given index 16 // (in bytes). 17 CompressedPageSize(int) int64 18 19 // FirstRowIndex returns the the first row in the page at the given index. 20 // 21 // The returned row index is based on the row group that the page belongs 22 // to, the first row has index zero. 23 FirstRowIndex(int) int64 24 } 25 26 type fileOffsetIndex format.OffsetIndex 27 28 func (i *fileOffsetIndex) NumPages() int { 29 return len(i.PageLocations) 30 } 31 32 func (i *fileOffsetIndex) Offset(j int) int64 { 33 return i.PageLocations[j].Offset 34 } 35 36 func (i *fileOffsetIndex) CompressedPageSize(j int) int64 { 37 return int64(i.PageLocations[j].CompressedPageSize) 38 } 39 40 func (i *fileOffsetIndex) FirstRowIndex(j int) int64 { 41 return i.PageLocations[j].FirstRowIndex 42 } 43 44 type emptyOffsetIndex struct{} 45 46 func (emptyOffsetIndex) NumPages() int { return 0 } 47 func (emptyOffsetIndex) Offset(int) int64 { return 0 } 48 func (emptyOffsetIndex) CompressedPageSize(int) int64 { return 0 } 49 func (emptyOffsetIndex) FirstRowIndex(int) int64 { return 0 } 50 51 type booleanOffsetIndex struct{ page *booleanPage } 52 53 func (i booleanOffsetIndex) NumPages() int { return 1 } 54 func (i booleanOffsetIndex) Offset(int) int64 { return 0 } 55 func (i booleanOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 56 func (i booleanOffsetIndex) FirstRowIndex(int) int64 { return 0 } 57 58 type int32OffsetIndex struct{ page *int32Page } 59 60 func (i int32OffsetIndex) NumPages() int { return 1 } 61 func (i int32OffsetIndex) Offset(int) int64 { return 0 } 62 func (i int32OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 63 func (i int32OffsetIndex) FirstRowIndex(int) int64 { return 0 } 64 65 type int64OffsetIndex struct{ page *int64Page } 66 67 func (i int64OffsetIndex) NumPages() int { return 1 } 68 func (i int64OffsetIndex) Offset(int) int64 { return 0 } 69 func (i int64OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 70 func (i int64OffsetIndex) FirstRowIndex(int) int64 { return 0 } 71 72 type int96OffsetIndex struct{ page *int96Page } 73 74 func (i int96OffsetIndex) NumPages() int { return 1 } 75 func (i int96OffsetIndex) Offset(int) int64 { return 0 } 76 func (i int96OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 77 func (i int96OffsetIndex) FirstRowIndex(int) int64 { return 0 } 78 79 type floatOffsetIndex struct{ page *floatPage } 80 81 func (i floatOffsetIndex) NumPages() int { return 1 } 82 func (i floatOffsetIndex) Offset(int) int64 { return 0 } 83 func (i floatOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 84 func (i floatOffsetIndex) FirstRowIndex(int) int64 { return 0 } 85 86 type doubleOffsetIndex struct{ page *doublePage } 87 88 func (i doubleOffsetIndex) NumPages() int { return 1 } 89 func (i doubleOffsetIndex) Offset(int) int64 { return 0 } 90 func (i doubleOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 91 func (i doubleOffsetIndex) FirstRowIndex(int) int64 { return 0 } 92 93 type byteArrayOffsetIndex struct{ page *byteArrayPage } 94 95 func (i byteArrayOffsetIndex) NumPages() int { return 1 } 96 func (i byteArrayOffsetIndex) Offset(int) int64 { return 0 } 97 func (i byteArrayOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 98 func (i byteArrayOffsetIndex) FirstRowIndex(int) int64 { return 0 } 99 100 type fixedLenByteArrayOffsetIndex struct{ page *fixedLenByteArrayPage } 101 102 func (i fixedLenByteArrayOffsetIndex) NumPages() int { return 1 } 103 func (i fixedLenByteArrayOffsetIndex) Offset(int) int64 { return 0 } 104 func (i fixedLenByteArrayOffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 105 func (i fixedLenByteArrayOffsetIndex) FirstRowIndex(int) int64 { return 0 } 106 107 type uint32OffsetIndex struct{ page *uint32Page } 108 109 func (i uint32OffsetIndex) NumPages() int { return 1 } 110 func (i uint32OffsetIndex) Offset(int) int64 { return 0 } 111 func (i uint32OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 112 func (i uint32OffsetIndex) FirstRowIndex(int) int64 { return 0 } 113 114 type uint64OffsetIndex struct{ page *uint64Page } 115 116 func (i uint64OffsetIndex) NumPages() int { return 1 } 117 func (i uint64OffsetIndex) Offset(int) int64 { return 0 } 118 func (i uint64OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 119 func (i uint64OffsetIndex) FirstRowIndex(int) int64 { return 0 } 120 121 type be128OffsetIndex struct{ page *be128Page } 122 123 func (i be128OffsetIndex) NumPages() int { return 1 } 124 func (i be128OffsetIndex) Offset(int) int64 { return 0 } 125 func (i be128OffsetIndex) CompressedPageSize(int) int64 { return i.page.Size() } 126 func (i be128OffsetIndex) FirstRowIndex(int) int64 { return 0 }