diff --git a/lib/logstorage/stats_uniq_values_test.go b/lib/logstorage/stats_uniq_values_test.go index ddcfcc030..70d25d200 100644 --- a/lib/logstorage/stats_uniq_values_test.go +++ b/lib/logstorage/stats_uniq_values_test.go @@ -13,6 +13,7 @@ func TestParseStatsUniqValuesSuccess(t *testing.T) { f(`uniq_values(*)`) f(`uniq_values(a)`) f(`uniq_values(a, b)`) + f(`uniq_values(a, b) limit 10`) } func TestParseStatsUniqValuesFailure(t *testing.T) { @@ -24,6 +25,8 @@ func TestParseStatsUniqValuesFailure(t *testing.T) { f(`uniq_values`) f(`uniq_values(a b)`) f(`uniq_values(x) y`) + f(`uniq_values(x) limit`) + f(`uniq_values(x) limit N`) } func TestStatsUniqValues(t *testing.T) { @@ -52,6 +55,26 @@ func TestStatsUniqValues(t *testing.T) { }, }) + f("stats uniq_values(*) limit 1999 as x", [][]Field{ + { + {"_msg", `abc`}, + {"a", `2`}, + {"b", `3`}, + }, + { + {"_msg", `def`}, + {"a", `1`}, + }, + { + {"a", `-3`}, + {"b", `54`}, + }, + }, [][]Field{ + { + {"x", `["-3","1","2","3","54","abc","def"]`}, + }, + }) + f("stats uniq_values(a) as x", [][]Field{ { {"_msg", `abc`}, @@ -237,6 +260,36 @@ func TestStatsUniqValues(t *testing.T) { }, }) + f("stats by (a) uniq_values(*) limit 100 as x", [][]Field{ + { + {"_msg", `abc`}, + {"a", `1`}, + {"b", `3`}, + }, + { + {"_msg", `def`}, + {"a", `1`}, + {"c", "3"}, + }, + { + {"a", `3`}, + {"b", `5`}, + }, + { + {"a", `3`}, + {"b", `7`}, + }, + }, [][]Field{ + { + {"a", "1"}, + {"x", `["1","3","abc","def"]`}, + }, + { + {"a", "3"}, + {"x", `["3","5","7"]`}, + }, + }) + f("stats by (a) uniq_values(c) as x", [][]Field{ { {"_msg", `abc`}, diff --git a/lib/logstorage/stats_values_test.go b/lib/logstorage/stats_values_test.go new file mode 100644 index 000000000..34b621db3 --- /dev/null +++ b/lib/logstorage/stats_values_test.go @@ -0,0 +1,30 @@ +package logstorage + +import ( + "testing" +) + +func TestParseStatsValuesSuccess(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParseStatsFuncSuccess(t, pipeStr) + } + + f(`values(*)`) + f(`values(a)`) + f(`values(a, b)`) + f(`values(a, b) limit 10`) +} + +func TestParseStatsValuesFailure(t *testing.T) { + f := func(pipeStr string) { + t.Helper() + expectParseStatsFuncFailure(t, pipeStr) + } + + f(`values`) + f(`values(a b)`) + f(`values(x) y`) + f(`values(a, b) limit`) + f(`values(a, b) limit foo`) +}