Skip to content

Commit

Permalink
Clean output of analyse a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
xeals committed Apr 26, 2018
1 parent c9167a8 commit cf07cd1
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/analyse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/pkg/errors"
"github.com/urfave/cli"
"github.com/xeals/signal-back/signal"
"github.com/xeals/signal-back/types"
)

Expand Down Expand Up @@ -37,12 +38,17 @@ var Analyse = cli.Command{
}

a, err := AnalyseTables(bf)
fmt.Println("This is still largely in flux and reflects whatever task I was having issues with at the time.\n")
fmt.Println(a)

return nil
fmt.Println("part:", len(examples["insert_into_part"].GetParameters()), examples["insert_into_part"])

return errors.WithMessage(err, "failed to analyse tables")
},
}

var examples = map[string]*signal.SqlStatement{}

// AnalyseTables calculates the frequency of all records in the backup file.
func AnalyseTables(bf *types.BackupFile) (map[string]int, error) {
counts := make(map[string]int)
Expand Down Expand Up @@ -75,37 +81,37 @@ func AnalyseTables(bf *types.BackupFile) (map[string]int, error) {
if stmt := f.GetStatement(); stmt != nil {
if strings.HasPrefix(*stmt.Statement, "DROP TABLE") {
if counts["drop_table"] == 0 {
fmt.Println(stmt)
examples["drop_table"] = stmt
}
counts["drop_table"]++
continue
}
if strings.HasPrefix(*stmt.Statement, "CREATE TABLE") {
if counts["create_table"] == 0 {
fmt.Println(stmt)
examples["create_table"] = stmt
}
counts["create_table"]++
continue
}
if strings.HasPrefix(*stmt.Statement, "DROP INDEX") {
if counts["drop_index"] == 0 {
fmt.Println(stmt)
examples["drop_index"] = stmt
}
counts["drop_index"]++
continue
}
if strings.HasPrefix(*stmt.Statement, "CREATE INDEX") ||
strings.HasPrefix(*stmt.Statement, "CREATE UNIQUE INDEX") {
if counts["create_index"] == 0 {
fmt.Println(stmt)
examples["create_index"] = stmt
}
counts["create_index"]++
continue
}
if strings.HasPrefix(*stmt.Statement, "INSERT INTO") {
table := strings.Split(*stmt.Statement, " ")[2]
if counts["insert_into_"+table] == 0 {
fmt.Println(stmt)
examples["insert_into_"+table] = stmt
}
counts["insert_into_"+table]++
continue
Expand Down

0 comments on commit cf07cd1

Please sign in to comment.