Skip to content

Commit

Permalink
bugfix: csv flag handling was broken
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Taylor <[email protected]>
  • Loading branch information
systay committed Jan 9, 2025
1 parent 15a6586 commit fe3bf20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
3 changes: 3 additions & 0 deletions go/cmd/flag_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,5 +89,8 @@ func csvFlagsToConfig(cmd *cobra.Command, flags csvFlags) data.CSVConfig {
if cmd.Flags().Changed("csv-timestamp-field") {
c.TimestampField = &flags.timestampField
}
if cmd.Flags().Changed("csv-header") {
c.Header = flags.header
}
return c
}
4 changes: 1 addition & 3 deletions go/cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ func keysCmd() *cobra.Command {
Short: "Runs vexplain keys on all queries of the test file",
Example: "vt keys file.test",
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, _ []string) {
csvConfig = csvFlagsToConfig(cmd, *flags)
},
RunE: func(c *cobra.Command, args []string) error {
csvConfig = csvFlagsToConfig(c, *flags)
cfg := keys.Config{
FileName: args[0],
}
Expand Down
11 changes: 8 additions & 3 deletions go/data/csv_log_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package data

import (
"encoding/csv"
"fmt"
"io"
"os"
"strconv"
Expand Down Expand Up @@ -81,14 +82,18 @@ func (c *csvLogReaderState) Next() (Query, bool) {

l, _ := c.reader.FieldPos(0)

helpfulPanic := func(err error, val string) {
panic(fmt.Sprintf("%s at line: %d for value: %s", err.Error(), l, val))
}

recordToInt := func(idx *int) int {
if idx == nil {
return 0
}
val := record[*idx]
i, err := strconv.Atoi(val)
if err != nil {
panic(err)
helpfulPanic(err, val)
}
return i
}
Expand All @@ -100,7 +105,7 @@ func (c *csvLogReaderState) Next() (Query, bool) {
val := record[*idx]
f, err := strconv.ParseFloat(val, 64)
if err != nil {
panic(err)
helpfulPanic(err, val)
}
return f
}
Expand All @@ -112,7 +117,7 @@ func (c *csvLogReaderState) Next() (Query, bool) {
val := record[*idx]
t, err := time.Parse(time.DateTime, val)
if err != nil {
panic(err)
helpfulPanic(err, val)
}
return t.Unix()
}
Expand Down

0 comments on commit fe3bf20

Please sign in to comment.