Skip to content

Commit

Permalink
fix a bug in which New<FIELD> funcs were being defined multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Swank authored and Craig Swank committed Feb 12, 2019
1 parent 5cc409f commit a46f733
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions cmd/parquetgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ var funcs = template.FuncMap{
"removeStar": func(s string) string {
return strings.Replace(s, "*", "", 1)
},
"dedupe": func(fields []parse.Field) []parse.Field {
seen := map[string]bool{}
out := make([]parse.Field, 0, len(fields))
for _, f := range fields {
_, ok := seen[f.FieldType]
if !ok {
out = append(out, f)
seen[f.FieldType] = true
}
}
return out
},
}

type fieldType struct {
Expand Down Expand Up @@ -55,13 +67,12 @@ func main() {
log.Fatal("not generating parquet.go (-ignore set to false), err: ", result.Errors)
}

tmpl, err := template.New("output").Parse(tpl)
tmpl := template.New("output").Funcs(funcs)
tmpl, err = tmpl.Parse(tpl)
if err != nil {
log.Fatal(err)
}

tmpl.Funcs(funcs)

for _, t := range []string{
requiredTpl,
optionalTpl,
Expand Down Expand Up @@ -797,7 +808,7 @@ func (p *ParquetReader) Scan(x *{{.Type}}) {
}
}
{{range .Fields}}
{{range dedupe .Fields}}
{{if eq .Category "numeric"}}
{{ template "requiredField" .}}
{{end}}
Expand Down

0 comments on commit a46f733

Please sign in to comment.