keep field name as is for csv timestamp column (#8440)
This commit is contained in:
parent
8ad288bad4
commit
247230c5c9
|
|
@ -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.
|
// Try explicit conversion only when column types is defined.
|
||||||
if len(p.ColumnTypes) > 0 {
|
if len(p.ColumnTypes) > 0 {
|
||||||
// Throw error if current column count exceeds defined types.
|
// Throw error if current column count exceeds defined types.
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,26 @@ func TestTimestamp(t *testing.T) {
|
||||||
require.Equal(t, metrics[1].Time().UnixNano(), int64(1257609906000000000))
|
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) {
|
func TestTimestampError(t *testing.T) {
|
||||||
p, err := NewParser(
|
p, err := NewParser(
|
||||||
&Config{
|
&Config{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue