diff --git a/pkg/csv2lp/csv_table.go b/pkg/csv2lp/csv_table.go index ae20a306052..0927f8cca13 100644 --- a/pkg/csv2lp/csv_table.go +++ b/pkg/csv2lp/csv_table.go @@ -46,7 +46,7 @@ type CsvTableColumn struct { // TimeZone of dateTime column, applied when parsing dateTime DataType TimeZone *time.Location // ParseF is an optional function used to convert column's string value to interface{} - ParseF func(string) (interface{}, error) + ParseF func(value string, lineNumber int) (interface{}, error) // escapedLabel contains escaped label that can be directly used in line protocol escapedLabel string diff --git a/pkg/csv2lp/data_conversion.go b/pkg/csv2lp/data_conversion.go index 74d39420522..5e519aaebc6 100644 --- a/pkg/csv2lp/data_conversion.go +++ b/pkg/csv2lp/data_conversion.go @@ -133,7 +133,7 @@ func toTypedValue(val string, column *CsvTableColumn, lineNumber int) (interface dataType := column.DataType dataFormat := column.DataFormat if column.ParseF != nil { - return column.ParseF(val) + return column.ParseF(val, lineNumber) } switch dataType { case stringDatatype: @@ -267,7 +267,7 @@ func CreateDecoder(encoding string) (func(io.Reader) io.Reader, error) { } // createBoolParseFn returns a function that converts a string value to boolean according to format "true,yes,1:false,no,0" -func createBoolParseFn(format string) func(string) (interface{}, error) { +func createBoolParseFn(format string) func(string, int) (interface{}, error) { var err error = nil truthy := []string{} falsy := []string{} @@ -284,7 +284,7 @@ func createBoolParseFn(format string) func(string) (interface{}, error) { falsy = strings.Split(f, ",") } } - return func(val string) (interface{}, error) { + return func(val string, _lineNumber int) (interface{}, error) { if err != nil { return nil, err } diff --git a/pkg/csv2lp/data_conversion_test.go b/pkg/csv2lp/data_conversion_test.go index 5f0a81e646d..93d01a6201a 100644 --- a/pkg/csv2lp/data_conversion_test.go +++ b/pkg/csv2lp/data_conversion_test.go @@ -336,7 +336,7 @@ func Test_CreateBoolParseFn(t *testing.T) { fn := createBoolParseFn(test.format) for j, pair := range test.pair { t.Run(fmt.Sprint(i)+"_"+fmt.Sprint(j), func(t *testing.T) { - result, err := fn(pair.value) + result, err := fn(pair.value, 1) switch pair.expect { case "true": require.Equal(t, true, result)