Skip to content

Commit 695fa06

Browse files
authored
stats: Add total row (#922)
1 parent 808dfa8 commit 695fa06

File tree

1 file changed

+38
-11
lines changed

1 file changed

+38
-11
lines changed

cmd/parquet-tool/cmd/stats.go

+38-11
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,48 @@ func runStats(file string) error {
7777
keys := maps.Keys(s)
7878
slices.Sort(keys)
7979

80+
var (
81+
totalCompressedSize int64
82+
totalUncompressedSize int64
83+
totalByteSize int64
84+
)
8085
for _, k := range keys {
8186
row := s[k]
82-
table.Append(
83-
[]string{
84-
k,
85-
row.Type,
86-
fmt.Sprintf("%d", row.NumVal),
87-
row.Encoding,
88-
humanize.Bytes(uint64(row.TotalCompressedSize)),
89-
humanize.Bytes(uint64(row.TotalUncompressedSize)),
90-
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize-row.TotalCompressedSize)/float64(row.TotalCompressedSize)*100),
91-
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize)/float64(row.TotalByteSize)*100),
92-
})
87+
table.Append([]string{
88+
k,
89+
row.Type,
90+
fmt.Sprintf("%d", row.NumVal),
91+
row.Encoding,
92+
humanize.Bytes(uint64(row.TotalCompressedSize)),
93+
humanize.Bytes(uint64(row.TotalUncompressedSize)),
94+
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize-row.TotalCompressedSize)/float64(row.TotalCompressedSize)*100),
95+
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize)/float64(row.TotalByteSize)*100),
96+
})
97+
98+
totalCompressedSize += row.TotalCompressedSize
99+
totalUncompressedSize += row.TotalUncompressedSize
100+
totalByteSize += row.TotalByteSize
93101
}
102+
103+
table.Append([]string{
104+
"Total",
105+
"",
106+
"",
107+
"",
108+
humanize.Bytes(uint64(totalCompressedSize)),
109+
humanize.Bytes(uint64(totalUncompressedSize)),
110+
"",
111+
"",
112+
})
94113
table.Render()
95114

96115
return nil
97116
}
117+
118+
func sum(a []int64) int64 {
119+
var s int64
120+
for _, v := range a {
121+
s += v
122+
}
123+
return s
124+
}

0 commit comments

Comments
 (0)