VictoriaMetrics/lib/logstorage/stats_row_min_test.go

286 lines
3.7 KiB
Go
Raw Normal View History

2024-05-22 21:01:20 +02:00
package logstorage
import (
"testing"
)
2024-05-30 16:19:23 +02:00
func TestParseStatsRowMinSuccess(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string) {
t.Helper()
expectParseStatsFuncSuccess(t, pipeStr)
}
2024-05-30 16:19:23 +02:00
f(`row_min(foo)`)
f(`row_min(foo, bar)`)
f(`row_min(foo, bar, baz)`)
2024-05-22 21:01:20 +02:00
}
2024-05-30 16:19:23 +02:00
func TestParseStatsRowMinFailure(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string) {
t.Helper()
expectParseStatsFuncFailure(t, pipeStr)
}
2024-05-30 16:19:23 +02:00
f(`row_min`)
f(`row_min()`)
f(`row_min(x) bar`)
2024-05-22 21:01:20 +02:00
}
2024-05-30 16:19:23 +02:00
func TestStatsRowMin(t *testing.T) {
2024-05-22 21:01:20 +02:00
f := func(pipeStr string, rows, rowsExpected [][]Field) {
t.Helper()
expectPipeResults(t, pipeStr, rows, rowsExpected)
}
2024-05-30 16:19:23 +02:00
f("stats row_min(a) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{"_msg":"def","a":"1"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_min(foo) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_min(b, a) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
{"c", "1232"},
},
}, [][]Field{
{
{"x", `{"a":"2"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats row_min(b, a, x, b) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
{"c", "1232"},
},
}, [][]Field{
{
{"x", `{"a":"2","b":"3"}`},
2024-05-22 21:01:20 +02:00
},
})
2024-05-30 16:19:23 +02:00
f("stats row_min(a) if (b:*) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `54`},
},
}, [][]Field{
{
{"x", `{"_msg":"abc","a":"2","b":"3"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (b) row_min(a) if (b:*) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `2`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `-12.34`},
{"b", "3"},
},
{
{"a", `3`},
{"c", `54`},
},
}, [][]Field{
{
{"b", "3"},
{"x", `{"_msg":"def","a":"-12.34","b":"3"}`},
},
{
{"b", ""},
{"x", `{}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_min(b) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"b", `5`},
},
{
{"a", `3`},
{"b", `7`},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{"_msg":"abc","a":"1","b":"3"}`},
},
{
{"a", "3"},
{"x", `{"a":"3","b":"5"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_min(c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
},
{
{"a", `3`},
{"c", `foo`},
},
{
{"a", `3`},
{"b", `7`},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{}`},
},
{
{"a", "3"},
{"x", `{"a":"3","c":"foo"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a) row_min(b, c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `34`},
},
{
{"_msg", `def`},
{"a", `1`},
{"c", "3"},
},
{
{"a", `3`},
{"b", `5`},
{"c", "foo"},
},
{
{"a", `3`},
{"b", `7`},
},
}, [][]Field{
{
{"a", "1"},
{"x", `{}`},
2024-05-22 21:01:20 +02:00
},
{
{"a", "3"},
{"x", `{"c":"foo"}`},
},
})
2024-05-30 16:19:23 +02:00
f("stats by (a, b) row_min(c) as x", [][]Field{
2024-05-22 21:01:20 +02:00
{
{"_msg", `abc`},
{"a", `1`},
{"b", `3`},
},
{
{"_msg", `def`},
{"a", `1`},
{"c", "foo"},
},
{
{"a", `3`},
{"b", `5`},
{"c", "4"},
},
}, [][]Field{
{
{"a", "1"},
{"b", "3"},
{"x", `{}`},
},
{
{"a", "1"},
{"b", ""},
2024-05-25 21:36:16 +02:00
{"x", `{"_msg":"def","a":"1","c":"foo"}`},
2024-05-22 21:01:20 +02:00
},
{
{"a", "3"},
{"b", "5"},
{"x", `{"a":"3","b":"5","c":"4"}`},
},
})
}