mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
app/vmselect/graphite: properly handle -N index for the array of N items
This is a follow-up for 70cd09e736
Updates https://github.com/VictoriaMetrics/VictoriaMetrics/pull/5581
This commit is contained in:
parent
30d77393a5
commit
a9fd130980
2 changed files with 18 additions and 4 deletions
|
@ -3600,11 +3600,11 @@ func groupSeriesByNodes(ss []*series, nodes []graphiteql.Expr) map[string][]*ser
|
|||
}
|
||||
|
||||
func getAbsoluteNodeIndex(index, size int) int {
|
||||
// handling the negative index case
|
||||
if index < 0 && index+size > 0 {
|
||||
index = index + size
|
||||
// Handle the negative index case as Python does
|
||||
if index < 0 {
|
||||
index = size + index
|
||||
}
|
||||
if index >= size || index < 0 {
|
||||
if index < 0 || index >= size {
|
||||
return -1
|
||||
}
|
||||
return index
|
||||
|
|
|
@ -92,4 +92,18 @@ func TestGetAbsoluteNodeIndex(t *testing.T) {
|
|||
f(0, 1, 0)
|
||||
f(-1, 3, 2)
|
||||
f(-3, 1, -1)
|
||||
f(-1, 1, 0)
|
||||
f(-2, 1, -1)
|
||||
f(3, 2, -1)
|
||||
f(2, 2, -1)
|
||||
f(1, 2, 1)
|
||||
f(0, 2, 0)
|
||||
f(-1, 2, 1)
|
||||
f(-2, 2, 0)
|
||||
f(-3, 2, -1)
|
||||
f(-5, 2, -1)
|
||||
f(-1, 100, 99)
|
||||
f(-99, 100, 1)
|
||||
f(-100, 100, 0)
|
||||
f(-101, 100, -1)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue