mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-05 01:01:09 +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.
286 lines
3.7 KiB
Go
286 lines
3.7 KiB
Go
package logstorage
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseStatsRowMinSuccess(t *testing.T) {
|
|
f := func(pipeStr string) {
|
|
t.Helper()
|
|
expectParseStatsFuncSuccess(t, pipeStr)
|
|
}
|
|
|
|
f(`row_min(foo)`)
|
|
f(`row_min(foo, bar)`)
|
|
f(`row_min(foo, bar, baz)`)
|
|
}
|
|
|
|
func TestParseStatsRowMinFailure(t *testing.T) {
|
|
f := func(pipeStr string) {
|
|
t.Helper()
|
|
expectParseStatsFuncFailure(t, pipeStr)
|
|
}
|
|
|
|
f(`row_min`)
|
|
f(`row_min()`)
|
|
f(`row_min(x) bar`)
|
|
}
|
|
|
|
func TestStatsRowMin(t *testing.T) {
|
|
f := func(pipeStr string, rows, rowsExpected [][]Field) {
|
|
t.Helper()
|
|
expectPipeResults(t, pipeStr, rows, rowsExpected)
|
|
}
|
|
|
|
f("stats row_min(a) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"_msg":"def","a":"1"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_min(foo) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_min(b, a) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
{"c", "1232"},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"a":"2"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_min(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":"2","b":"3"}`},
|
|
},
|
|
})
|
|
|
|
f("stats row_min(a) if (b:*) as x", [][]Field{
|
|
{
|
|
{"_msg", `abc`},
|
|
{"a", `2`},
|
|
{"b", `3`},
|
|
},
|
|
{
|
|
{"_msg", `def`},
|
|
{"a", `1`},
|
|
},
|
|
{
|
|
{"a", `3`},
|
|
{"b", `54`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"x", `{"_msg":"abc","a":"2","b":"3"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (b) row_min(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":"def","a":"-12.34","b":"3"}`},
|
|
},
|
|
{
|
|
{"b", ""},
|
|
{"x", `{}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a) row_min(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":"5"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a) row_min(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_min(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`},
|
|
},
|
|
}, [][]Field{
|
|
{
|
|
{"a", "1"},
|
|
{"x", `{}`},
|
|
},
|
|
{
|
|
{"a", "3"},
|
|
{"x", `{"c":"foo"}`},
|
|
},
|
|
})
|
|
|
|
f("stats by (a, b) row_min(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"}`},
|
|
},
|
|
})
|
|
}
|