mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-15 00:13:30 +01:00
app/vmselect/promql: allow nested parens
This commit is contained in:
parent
d2619d6dce
commit
f7da9b2db2
@ -4204,6 +4204,35 @@ func TestExecSuccess(t *testing.T) {
|
|||||||
resultExpected := []netstorage.Result{r1, r2}
|
resultExpected := []netstorage.Result{r1, r2}
|
||||||
f(q, resultExpected)
|
f(q, resultExpected)
|
||||||
})
|
})
|
||||||
|
t.Run(`((1),(2,3))`, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
q := `((
|
||||||
|
alias(1, "x1"),
|
||||||
|
),(
|
||||||
|
alias(2, "x2"),
|
||||||
|
alias(3, "x3"),
|
||||||
|
))`
|
||||||
|
r1 := netstorage.Result{
|
||||||
|
MetricName: metricNameExpected,
|
||||||
|
Values: []float64{1, 1, 1, 1, 1, 1},
|
||||||
|
Timestamps: timestampsExpected,
|
||||||
|
}
|
||||||
|
r1.MetricName.MetricGroup = []byte("x1")
|
||||||
|
r2 := netstorage.Result{
|
||||||
|
MetricName: metricNameExpected,
|
||||||
|
Values: []float64{2, 2, 2, 2, 2, 2},
|
||||||
|
Timestamps: timestampsExpected,
|
||||||
|
}
|
||||||
|
r2.MetricName.MetricGroup = []byte("x2")
|
||||||
|
r3 := netstorage.Result{
|
||||||
|
MetricName: metricNameExpected,
|
||||||
|
Values: []float64{3, 3, 3, 3, 3, 3},
|
||||||
|
Timestamps: timestampsExpected,
|
||||||
|
}
|
||||||
|
r3.MetricName.MetricGroup = []byte("x3")
|
||||||
|
resultExpected := []netstorage.Result{r1, r2, r3}
|
||||||
|
f(q, resultExpected)
|
||||||
|
})
|
||||||
t.Run(`union(more-than-two)`, func(t *testing.T) {
|
t.Run(`union(more-than-two)`, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
q := `union(
|
q := `union(
|
||||||
|
@ -116,13 +116,17 @@ func removeParensExpr(e expr) expr {
|
|||||||
return fe
|
return fe
|
||||||
}
|
}
|
||||||
if pe, ok := e.(*parensExpr); ok {
|
if pe, ok := e.(*parensExpr); ok {
|
||||||
|
args := *pe
|
||||||
|
for i, arg := range args {
|
||||||
|
args[i] = removeParensExpr(arg)
|
||||||
|
}
|
||||||
if len(*pe) == 1 {
|
if len(*pe) == 1 {
|
||||||
return removeParensExpr((*pe)[0])
|
return args[0]
|
||||||
}
|
}
|
||||||
// Treat parensExpr as a function with empty name, i.e. union()
|
// Treat parensExpr as a function with empty name, i.e. union()
|
||||||
fe := &funcExpr{
|
fe := &funcExpr{
|
||||||
Name: "",
|
Name: "",
|
||||||
Args: *pe,
|
Args: args,
|
||||||
}
|
}
|
||||||
return fe
|
return fe
|
||||||
}
|
}
|
||||||
|
@ -252,6 +252,8 @@ func TestParsePromQLSuccess(t *testing.T) {
|
|||||||
another(`(-foo + ((bar) / (baz))) + ((23))`, `((0 - foo) + (bar / baz)) + 23`)
|
another(`(-foo + ((bar) / (baz))) + ((23))`, `((0 - foo) + (bar / baz)) + 23`)
|
||||||
another(`(FOO + ((Bar) / (baZ))) + ((23))`, `(FOO + (Bar / baZ)) + 23`)
|
another(`(FOO + ((Bar) / (baZ))) + ((23))`, `(FOO + (Bar / baZ)) + 23`)
|
||||||
same(`(foo, bar)`)
|
same(`(foo, bar)`)
|
||||||
|
another(`((foo, bar),(baz))`, `((foo, bar), baz)`)
|
||||||
|
same(`(foo, (bar, baz), ((x, y), (z, y), xx))`)
|
||||||
another(`1+(foo, bar,)`, `1 + (foo, bar)`)
|
another(`1+(foo, bar,)`, `1 + (foo, bar)`)
|
||||||
another(`((foo(bar,baz)), (1+(2)+(3,4)+()))`, `(foo(bar, baz), (3 + (3, 4)) + ())`)
|
another(`((foo(bar,baz)), (1+(2)+(3,4)+()))`, `(foo(bar, baz), (3 + (3, 4)) + ())`)
|
||||||
same(`()`)
|
same(`()`)
|
||||||
|
Loading…
Reference in New Issue
Block a user