keep field name as is for csv timestamp column (#8440)

This commit is contained in:
Stephanie Engel 2020-11-20 09:52:07 -06:00 committed by GitHub
parent 8ad288bad4
commit 247230c5c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -204,6 +204,12 @@ outer:
}
}
// If the field name is the timestamp column, then keep field name as is.
if fieldName == p.TimestampColumn {
recordFields[fieldName] = value
continue
}
// Try explicit conversion only when column types is defined.
if len(p.ColumnTypes) > 0 {
// Throw error if current column count exceeds defined types.

View File

@ -85,6 +85,26 @@ func TestTimestamp(t *testing.T) {
require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906000000000))
}
func TestTimestampYYYYMMDDHHmm(t *testing.T) {
p, err := NewParser(
&Config{
HeaderRowCount: 1,
ColumnNames: []string{"first", "second", "third"},
MeasurementColumn: "third",
TimestampColumn: "first",
TimestampFormat: "200601021504",
TimeFunc: DefaultTime,
},
)
testCSV := `line1,line2,line3
200905231605,70,test_name
200907111605,80,test_name2`
metrics, err := p.Parse([]byte(testCSV))
require.NoError(t, err)
require.Equal(t, metrics[0].Time().UnixNano(), int64(1243094700000000000))
require.Equal(t, metrics[1].Time().UnixNano(), int64(1247328300000000000))
}
func TestTimestampError(t *testing.T) {
p, err := NewParser(
&Config{