2024-05-12 16:33:29 +02:00
|
|
|
package logstorage
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPipeStatsUpdateNeededFields(t *testing.T) {
|
|
|
|
f := func(s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected string) {
|
|
|
|
t.Helper()
|
2024-05-20 04:08:30 +02:00
|
|
|
expectPipeNeededFields(t, s, neededFields, unneededFields, neededFieldsExpected, unneededFieldsExpected)
|
2024-05-12 16:33:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// all the needed fields
|
|
|
|
f("stats count() r1", "*", "", "", "")
|
|
|
|
f("stats count(*) r1", "*", "", "", "")
|
|
|
|
f("stats count(f1,f2) r1", "*", "", "f1,f2", "")
|
|
|
|
f("stats count(f1,f2) r1, sum(f3,f4) r2", "*", "", "f1,f2,f3,f4", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "*", "", "b1,b2,f1,f2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1, count(f1,f3) r2", "*", "", "b1,b2,f1,f2,f3", "")
|
|
|
|
|
|
|
|
// all the needed fields, unneeded fields do not intersect with stats fields
|
|
|
|
f("stats count() r1", "*", "f1,f2", "", "")
|
|
|
|
f("stats count(*) r1", "*", "f1,f2", "", "")
|
|
|
|
f("stats count(f1,f2) r1", "*", "f3,f4", "f1,f2", "")
|
|
|
|
f("stats count(f1,f2) r1, sum(f3,f4) r2", "*", "f5,f6", "f1,f2,f3,f4", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "*", "f3,f4", "b1,b2,f1,f2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1, count(f1,f3) r2", "*", "f4,f5", "b1,b2,f1,f2,f3", "")
|
|
|
|
|
|
|
|
// all the needed fields, unneeded fields intersect with stats fields
|
|
|
|
f("stats count() r1", "*", "r1,r2", "", "")
|
|
|
|
f("stats count(*) r1", "*", "r1,r2", "", "")
|
|
|
|
f("stats count(f1,f2) r1", "*", "r1,r2", "", "")
|
|
|
|
f("stats count(f1,f2) r1, sum(f3,f4) r2", "*", "r1,r3", "f3,f4", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "*", "r1,r2", "b1,b2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "*", "r1,r2,b1", "b1,b2", "")
|
2024-05-20 04:08:30 +02:00
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "*", "r1,r2,b1,b2", "b1,b2", "")
|
2024-05-12 16:33:29 +02:00
|
|
|
f("stats by (b1,b2) count(f1,f2) r1, count(f1,f3) r2", "*", "r1,r3", "b1,b2,f1,f3", "")
|
|
|
|
|
|
|
|
// needed fields do not intersect with stats fields
|
|
|
|
f("stats count() r1", "r2", "", "", "")
|
|
|
|
f("stats count(*) r1", "r2", "", "", "")
|
|
|
|
f("stats count(f1,f2) r1", "r2", "", "", "")
|
|
|
|
f("stats count(f1,f2) r1, sum(f3,f4) r2", "r3", "", "", "")
|
2024-05-20 04:08:30 +02:00
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "r2", "", "b1,b2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1, count(f1,f3) r2", "r3", "", "b1,b2", "")
|
2024-05-12 16:33:29 +02:00
|
|
|
|
|
|
|
// needed fields intersect with stats fields
|
|
|
|
f("stats count() r1", "r1,r2", "", "", "")
|
|
|
|
f("stats count(*) r1", "r1,r2", "", "", "")
|
|
|
|
f("stats count(f1,f2) r1", "r1,r2", "", "f1,f2", "")
|
|
|
|
f("stats count(f1,f2) r1, sum(f3,f4) r2", "r1,r3", "", "f1,f2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1", "r1,r2", "", "b1,b2,f1,f2", "")
|
|
|
|
f("stats by (b1,b2) count(f1,f2) r1, count(f1,f3) r2", "r1,r3", "", "b1,b2,f1,f2", "")
|
|
|
|
}
|