VictoriaMetrics/lib/logstorage/pipe_field_names_test.go

101 lines
1.9 KiB
Go
Raw Normal View History

2024-05-20 04:08:30 +02:00
package logstorage
import (
"testing"
)
2024-05-22 21:01:20 +02:00
func TestParsePipeFieldNamesSuccess(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeSuccess(t, pipeStr)
}
2024-05-24 03:06:55 +02:00
f(`field_names`)
2024-05-22 21:01:20 +02:00
f(`field_names as x`)
}
func TestParsePipeFieldNamesFailure(t *testing.T) {
f := func(pipeStr string) {
t.Helper()
expectParsePipeFailure(t, pipeStr)
}
f(`field_names(foo)`)
f(`field_names a b`)
f(`field_names as`)
}
func TestPipeFieldNames(t *testing.T) {
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
// single row, result column doesn't clash with original columns
2024-05-24 03:06:55 +02:00
f("field_names", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `{"foo":"bar"}`},
{"a", `test`},
},
}, [][]Field{
{
2024-05-24 03:06:55 +02:00
{"name", "_msg"},
{"hits", "1"},
2024-05-22 21:01:20 +02:00
},
{
2024-05-24 03:06:55 +02:00
{"name", "a"},
{"hits", "1"},
2024-05-22 21:01:20 +02:00
},
})
// single row, result column do clashes with original columns
2024-05-24 03:06:55 +02:00
f("field_names as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"a", `test`},
2024-05-24 03:06:55 +02:00
{"b", "aaa"},
},
{
{"a", `bar`},
},
{
{"a", `bar`},
{"c", `bar`},
2024-05-22 21:01:20 +02:00
},
}, [][]Field{
{
2024-05-24 03:06:55 +02:00
{"x", "a"},
{"hits", "3"},
},
{
{"x", "b"},
{"hits", "1"},
2024-05-22 21:01:20 +02:00
},
{
2024-05-24 03:06:55 +02:00
{"x", "c"},
{"hits", "1"},
2024-05-22 21:01:20 +02:00
},
})
}
2024-05-20 04:08:30 +02:00
func TestPipeFieldNamesUpdateNeededFields(t *testing.T) {
f := func(s string, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
t.Helper()
expectPipeNeededFields(t, s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected)
}
// all the needed fields
f("field_names as f1", "*", "", "*", "")
// all the needed fields, unneeded fields do not intersect with src
f("field_names as f3", "*", "f1,f2", "*", "")
// all the needed fields, unneeded fields intersect with src
f("field_names as f1", "*", "s1,f1,f2", "*", "")
// needed fields do not intersect with src
f("field_names as f3", "f1,f2", "", "*", "")
// needed fields intersect with src
f("field_names as f1", "s1,f1,f2", "", "*", "")
}