-
Notifications
You must be signed in to change notification settings - Fork 64
/
rowgroup.go
68 lines (61 loc) 路 1.5 KB
/
rowgroup.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
66
67
68
package cmd
import (
"fmt"
"strconv"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
"github.com/spf13/cobra"
)
var rowgroupCmd = &cobra.Command{
Use: "rowgroup",
Example: "parquet-tool rg </path/to/parquet-file> <row_group_index>",
Short: "Dump the column index for a row group",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
rg, err := strconv.Atoi(args[1])
if err != nil {
return err
}
return rowgroup(args[0], rg)
},
}
func rowgroup(file string, rg int) error {
f, closer, err := openParquetFile(file)
if err != nil {
return fmt.Errorf("failed to open file :", err)
}
defer closer.Close()
t := table.New().
Border(lipgloss.NormalBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("99"))).
StyleFunc(func(row, col int) lipgloss.Style {
switch {
case row == 0:
return HeaderStyle
case row%2 == 0:
return EvenRowStyle
default:
return OddRowStyle
}
}).
Headers("Column", "Page", "Min", "Max", "Nulls")
defer fmt.Println(t)
rowgroup := f.RowGroups()[rg]
fields := rowgroup.Schema().Fields()
for i, chunk := range rowgroup.ColumnChunks() {
index, err := chunk.ColumnIndex()
if err != nil {
return err
}
for j := 0; j < index.NumPages(); j++ {
t.Row(
fields[i%len(fields)].Name(),
strconv.Itoa(j),
fmt.Sprintf("%v", index.MinValue(j)),
fmt.Sprintf("%v", index.MaxValue(j)),
fmt.Sprintf("%v", index.NullCount(j)),
)
}
}
return nil
}