Skip to content

Commit 3e3766c

Browse files
committed
output: use fieldNames
1 parent d989edf commit 3e3766c

File tree

3 files changed

+9
-29
lines changed

3 files changed

+9
-29
lines changed

output/sqlite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func NewSQLite(isRaw bool) func(baker.OutputParams) (baker.Output, error) {
146146
// an SQL table in the SQLite file.
147147
var fieldNames []string
148148
for _, fidx := range cfg.Fields {
149-
fieldNames = append(fieldNames, cfg.FieldName(fidx))
149+
fieldNames = append(fieldNames, cfg.FieldNames[fidx])
150150
}
151151

152152
sqlw := &SQLite{

output/sqlite_test.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,25 +45,15 @@ func makeWriter(t *testing.T, raw bool, path string, truncate bool) baker.Output
4545
return 0, false
4646
}
4747

48-
fieldName := func(i baker.FieldIndex) string {
49-
switch i {
50-
case 0:
51-
return "field0"
52-
case 1:
53-
return "field1"
54-
case 2:
55-
return "field2"
56-
}
57-
return ""
58-
}
48+
fieldNames := []string{"field0", "field1", "field2"}
5949

6050
params := baker.OutputParams{
6151
Fields: []baker.FieldIndex{0, 1, 2},
6252
Index: 0,
6353
ComponentParams: baker.ComponentParams{
6454
DecodedConfig: cfg,
6555
FieldByName: fieldByName,
66-
FieldName: fieldName,
56+
FieldNames: fieldNames,
6757
},
6858
}
6959
writer, err := newSQLiteWriter(raw)(params)
@@ -278,25 +268,15 @@ func TestSQLitePrePostCommands(t *testing.T) {
278268
return 0, false
279269
}
280270

281-
fieldName := func(i baker.FieldIndex) string {
282-
switch i {
283-
case 0:
284-
return "field0"
285-
case 1:
286-
return "field1"
287-
case 2:
288-
return "field2"
289-
}
290-
return ""
291-
}
271+
fieldNames := []string{"field0", "field1", "field2"}
292272

293273
cfg := baker.OutputParams{
294274
Fields: []baker.FieldIndex{0, 1, 2},
295275
Index: 0,
296276
ComponentParams: baker.ComponentParams{
297277
DecodedConfig: &config,
298278
FieldByName: fieldByName,
299-
FieldName: fieldName,
279+
FieldNames: fieldNames,
300280
},
301281
}
302282
writer, err := newSQLiteWriter(false)(cfg)

output/stats.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (s *fieldStats) add(ll baker.Record) {
116116
s.m[string(b)]++
117117
}
118118

119-
func (s *fieldStats) print(w io.Writer, fieldName func(baker.FieldIndex) string) error {
119+
func (s *fieldStats) print(w io.Writer, fieldNames []string) error {
120120
var smallest, biggest uint = math.MaxUint32, 0
121121

122122
qt := quantile.NewTargeted(0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.90, 0.95, 0.99)
@@ -135,7 +135,7 @@ func (s *fieldStats) print(w io.Writer, fieldName func(baker.FieldIndex) string)
135135
csvw := csv.NewWriter(w)
136136
if err := csvw.Write(
137137
[]string{fmt.Sprintf(
138-
"num samples (%s)", fieldName(s.field)),
138+
"num samples (%s)", fieldNames[s.field]),
139139
"smallest",
140140
"1st %%ile", "5th %%ile", "10th %%ile", "25th %%ile", "50th %%ile", "75th %%ile", "90th %%ile", "95th %%ile", "99th %%ile",
141141
"biggest"}); err != nil {
@@ -330,9 +330,9 @@ func (s *Stats) createStatsCSV() error {
330330
(&s.times).print(buf)
331331
}
332332
for i := range s.fields {
333-
fname := s.cfg.FieldName(s.fields[i].field)
333+
fname := s.cfg.FieldNames[s.fields[i].field]
334334
fmt.Fprintf(buf, "section,%s,distribution of number of log lines per distinct %s value\n", fname, fname)
335-
s.fields[i].print(buf, s.cfg.FieldName)
335+
s.fields[i].print(buf, s.cfg.FieldNames)
336336
}
337337
return ioutil.WriteFile(s.csvPath, buf.Bytes(), os.ModePerm)
338338

0 commit comments

Comments
 (0)