Skip to content

Commit

Permalink
Add path and better names in col-stats command
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed Jul 5, 2024
1 parent d950742 commit 59137c1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/inspect/col_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"io"
"strings"

"github.com/parquet-go/parquet-go"
"github.com/stoewer/parquet-cli/pkg/output"
Expand All @@ -21,6 +22,7 @@ var (
"Rows",
"Values",
"Nulls",
"Path",
}
columnStatHeaderFull = [...]any{
"Index",
Expand All @@ -39,6 +41,7 @@ var (
"Nulls",
"Page min nulls",
"Page max nulls",
"Path",
}
)

Expand All @@ -53,6 +56,7 @@ type ColumnStats struct {
Rows int64 `json:"rows"`
Values int64 `json:"values"`
Nulls int64 `json:"nulls"`
Path string `json:"path"`
}

func (rs *ColumnStats) Cells() []any {
Expand All @@ -67,6 +71,7 @@ func (rs *ColumnStats) Cells() []any {
rs.Rows,
rs.Values,
rs.Nulls,
rs.Path,
}
}

Expand Down Expand Up @@ -98,6 +103,7 @@ func (rs *ColumnStatsFull) Cells() []any {
rs.Nulls,
rs.PageMinNulls,
rs.PageMaxNulls,
rs.Path,
}
}

Expand Down Expand Up @@ -144,7 +150,7 @@ func (cc *ColStatCalculator) NextRow() (output.TableRow, error) {
stats := ColumnStatsFull{
ColumnStats: ColumnStats{
Index: col.Index(),
Name: col.Name(),
Name: PathToDisplayName(col.Path()),
MaxDef: col.MaxDefinitionLevel(),
MaxRep: col.MaxRepetitionLevel(),
},
Expand All @@ -163,6 +169,8 @@ func (cc *ColStatCalculator) NextRow() (output.TableRow, error) {
}
}

path := strings.Join(col.Path(), ".")

pages := chunk.Pages()
page, err := pages.ReadPage()
for err == nil {
Expand All @@ -179,6 +187,8 @@ func (cc *ColStatCalculator) NextRow() (output.TableRow, error) {
stats.PageMinRows = min(stats.PageMinRows, page.NumRows())
stats.PageMaxRows = max(stats.PageMaxRows, page.NumRows())

stats.Path = path

page, err = pages.ReadPage()
}

Expand Down

0 comments on commit 59137c1

Please sign in to comment.