mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
bac193e50b
Some checks are pending
build / Build (push) Waiting to run
CodeQL Go / Analyze (push) Waiting to run
main / lint (push) Waiting to run
main / test (test-full) (push) Blocked by required conditions
main / test (test-full-386) (push) Blocked by required conditions
main / test (test-pure) (push) Blocked by required conditions
publish-docs / Build (push) Waiting to run
Empty fields are treated as non-existing fields by VictoriaLogs data model. So there is no sense in returning empty fields in query results, since they may mislead and confuse users.
287 lines
3.7 KiB
Go
287 lines
3.7 KiB
Go
package logstorage
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseStatsRowMaxSuccess(t *testing.T) {
|
|
f := func(pipeStr string) {
|
|
t.Helper()
|
|
expectParseStatsFuncSuccess(t, pipeStr)
|
|
}
|
|
|
|
f(`row_max(foo)`)
|
|
f(`row_max(foo, bar)`)
|
|
f(`row_max(foo, bar, baz)`)
|
|
}
|
|
|
|
func TestParseStatsRowMaxFailure(t *testing.T) {
|
|
f := func(pipeStr string) {
|
|
t.Helper()
|
|
expectParseStatsFuncFailure(t, pipeStr)
|
|
}
|
|
|
|
f(`row_max`)
|
|
f(`row_max()`)
|
|
f(`row_max(x) bar`)
|
|
}
|
|
|
|
func TestStatsRowMax(t *testing.T) {
|
|
f := func(pipeStr string, rows, rowsExpected [][]Field) {
|
|
t.Helper()
|
|
expectPipeResults(t, pipeStr, rows, rowsExpected)
|
|
}
|
|
|
|
f("stats row_max(a) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"a":"3","b":"54"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_max(foo) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_max(b, a) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
{"c", "1232"},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"a":"3"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_max(b, a, x, b) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
{"c", "1232"},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"a":"3","b":"54"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_max(a) if (b:*) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"a":"3","b":"54"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (b) row_max(a) if (b:*) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `-12.34`},
|
|
{"b", "3"},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"c", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"b", "3"},
|
|
{"x", `{"_msg":"abc","a":"2","b":"3"}`},
|
|
},
|
|
{
|
|
{"b", ""},
|
|
{"x", `{}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a) row_max(b) as x", [][]Field{
|
|
{
|
|
{"_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":"7"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a) row_max(c) as x", [][]Field{
|
|
{
|
|
{"_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"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a) row_max(b, c) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `1`},
|
|
{"b", `34`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
{"c", "3"},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `5`},
|
|
{"c", "foo"},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `7`},
|
|
{"c", "bar"},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"a", "1"},
|
|
{"x", `{}`},
|
|
},
|
|
{
|
|
{"a", "3"},
|
|
{"x", `{"c":"bar"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a, b) row_max(c) as x", [][]Field{
|
|
{
|
|
{"_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", ""},
|
|
{"x", `{"_msg":"def","a":"1","c":"foo"}`},
|
|
},
|
|
{
|
|
{"a", "3"},
|
|
{"b", "5"},
|
|
{"x", `{"a":"3","b":"5","c":"4"}`},
|
|
},
|
|
})
|
|
}
|