Skip to content

Commit

Permalink
fix null value handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariel Abuel (NCS) committed Aug 31, 2021
1 parent 5cee75b commit 2549681
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions config/data_source_configuration_workbook.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,32 +372,42 @@ func reMapData(csv []map[string]string, mapping interface{}, filters []map[strin
replacer := strings.NewReplacer("s_", "", "string_", "")
new_key := strings.Title(replacer.Replace(k))
new_value[new_key] = value[k]
} else {
new_value[new_key] = ""
}
} else if strings.HasPrefix(k, "t_") || strings.HasPrefix(k, "tag_") {
if value[k] != "" {
replacer := strings.NewReplacer("t_", "", "tag_", "")
new_key := strings.Title(replacer.Replace(k))
new_tag[new_key] = value[k]
} else {
new_tag[new_key] = ""
}
} else if strings.HasPrefix(k, "n_") || strings.HasPrefix(k, "num_") || strings.HasPrefix(k, "number_") || strings.HasPrefix(k, "numeric_") {
if value[k] != "" {
replacer := strings.NewReplacer("n_", "", "num_", "", "number_", "", "numeric_", "")
new_key := replacer.Replace(k)
n, _ := strconv.ParseFloat(value[k], 64)
new_value[new_key] = n
} else {
new_value[new_key] = 0
}
} else if strings.HasPrefix(k, "b_") || strings.HasPrefix(k, "bool_") || strings.HasPrefix(k, "boolean_") {
if value[k] != "" {
replacer := strings.NewReplacer("b_", "", "bool_", "", "boolean_", "")
new_key := replacer.Replace(k)
val, _ := strconv.ParseBool(value[k])
new_value[new_key] = val
} else {
new_value[new_key] = false
}
} else if strings.HasPrefix(k, "l_") || strings.HasPrefix(k, "list_") {
if value[k] != "" {
replacer := strings.NewReplacer("l_", "", "list_", "")
new_key := replacer.Replace(k)
new_value[new_key] = strings.Split(value[k], ",")
} else {
new_value[new_key] = []string{}
}
} else if strings.HasPrefix(k, "m_") || strings.HasPrefix(k, "map_") {
if value[k] != "" {
Expand All @@ -410,6 +420,8 @@ func reMapData(csv []map[string]string, mapping interface{}, filters []map[strin
vmap[mlist[0]] = mlist[1]
}
new_value[new_key] = vmap
} else {
new_value[new_key] = map[string]string{}
}
} else {
new_value[k] = value[k]
Expand Down

0 comments on commit 2549681

Please sign in to comment.