forked from xitongsys/parquet-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sizetool.go
65 lines (58 loc) · 1.38 KB
/
sizetool.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
package sizetool
import (
"fmt"
"github.com/xitongsys/parquet-go/reader"
)
func GetParquetFileSize(name string, pr *reader.ParquetReader, pretty, uncompressedSize bool) string {
var size int64
if uncompressedSize {
size = getUncompressedSize(pr)
} else {
size = getCompressedSize(pr)
}
if pretty {
return fmt.Sprintf("%s: %s", name, getPrettySize(size))
}
return fmt.Sprintf("%s: %d bytes", name, size)
}
func getUncompressedSize(pr *reader.ParquetReader) int64 {
var size int64
for _, rg := range pr.Footer.RowGroups {
size += rg.TotalByteSize
}
return size
}
func getCompressedSize(pr *reader.ParquetReader) int64 {
var size int64
for _, rg := range pr.Footer.RowGroups {
for _, cc := range rg.Columns {
size += cc.MetaData.TotalCompressedSize
}
}
return size
}
func getPrettySize(size int64) string {
const (
oneKB = 1 << 10
oneMB = 1 << 20
oneGB = 1 << 30
oneTB = 1 << 40
onePB = 1 << 50
)
if size/oneKB < 1 {
return fmt.Sprintf("%d bytes", size)
}
if size/oneMB < 1 {
return fmt.Sprintf("%.3f KB", float64(size)/float64(oneKB))
}
if size/oneGB < 1 {
return fmt.Sprintf("%.3f MB", float64(size)/float64(oneMB))
}
if size/oneTB < 1 {
return fmt.Sprintf("%.3f GB", float64(size)/float64(oneGB))
}
if size/onePB < 1 {
return fmt.Sprintf("%.3f TB", float64(size)/float64(oneTB))
}
return fmt.Sprintf("%.3f PB", float64(size)/float64(onePB))
}