Skip to content

Commit

Permalink
stats: Add total row (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
brancz authored Jul 25, 2024
1 parent 808dfa8 commit 695fa06
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions cmd/parquet-tool/cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,21 +77,48 @@ func runStats(file string) error {
keys := maps.Keys(s)
slices.Sort(keys)

var (
totalCompressedSize int64
totalUncompressedSize int64
totalByteSize int64
)
for _, k := range keys {
row := s[k]
table.Append(
[]string{
k,
row.Type,
fmt.Sprintf("%d", row.NumVal),
row.Encoding,
humanize.Bytes(uint64(row.TotalCompressedSize)),
humanize.Bytes(uint64(row.TotalUncompressedSize)),
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize-row.TotalCompressedSize)/float64(row.TotalCompressedSize)*100),
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize)/float64(row.TotalByteSize)*100),
})
table.Append([]string{
k,
row.Type,
fmt.Sprintf("%d", row.NumVal),
row.Encoding,
humanize.Bytes(uint64(row.TotalCompressedSize)),
humanize.Bytes(uint64(row.TotalUncompressedSize)),
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize-row.TotalCompressedSize)/float64(row.TotalCompressedSize)*100),
fmt.Sprintf("%.2f", float64(row.TotalUncompressedSize)/float64(row.TotalByteSize)*100),
})

totalCompressedSize += row.TotalCompressedSize
totalUncompressedSize += row.TotalUncompressedSize
totalByteSize += row.TotalByteSize
}

table.Append([]string{
"Total",
"",
"",
"",
humanize.Bytes(uint64(totalCompressedSize)),
humanize.Bytes(uint64(totalUncompressedSize)),
"",
"",
})
table.Render()

return nil
}

func sum(a []int64) int64 {
var s int64
for _, v := range a {
s += v
}
return s
}

0 comments on commit 695fa06

Please sign in to comment.