-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatus.go
73 lines (65 loc) · 1.35 KB
/
status.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
69
70
71
72
73
package main
import (
"fmt"
"os"
"time"
"github.com/jedib0t/go-pretty/table"
"github.com/urfave/cli/v2"
)
func printStatus(conf *Config) error {
status := make(map[string][]Partition)
for _, table := range conf.Tables {
p, err := getCurrPartitions(conf.db, conf.Database, table.Name)
if err != nil {
return err
}
status[table.Name] = p
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(
table.Row{
"Table",
"Partition Name",
"Partition Expression",
"Partition Description",
"Number of Rows",
"Average Row Size (MB)",
"Index Size (MB)",
"Storage Size (MB)",
"Comment",
},
)
for tableName, partitions := range status {
for _, p := range partitions {
t.AppendRows(
[]table.Row{{
tableName,
p.Name,
p.Expression,
p.Description,
p.TableRows,
float32(p.AvgRowLength) / (1024 * 1024),
float32(p.IndexLength) / (1024 * 1024),
float32(p.DataLength) / (1024 * 1024),
p.PartitionComment,
}},
)
}
}
t.Render()
return nil
}
func status(c *cli.Context) (err error) {
conf, err := loadAndValidateConfig(c)
if err != nil {
return
}
return printStatus(conf)
}
func yearweek(_ *cli.Context) error {
now := time.Now()
yw := determineYearWeek(now)
fmt.Fprintf(os.Stdout, "%d is the yearweek for %s\n", yw, now.Format(time.UnixDate))
return nil
}