Fix sum(aggr_over_time) 'got 1 args' error (#3028) (#5414)

app/vmselect/promql/eval.go:evalAggrFunc shunts evaluation
of AggrFuncExpr over rollupFunc over MetricsExpr to an optimized
path. tryGetArgRollupFuncWithMetricExpr() checks whether expression
can be shunted, but it mangles the AggrFuncExpr when the aggregation
function has more than one argument. This results in queries like
`sum(aggr_over_time("avg_over_time",m))` failing with error message
'expecting at least 2 args to "aggr_over_time"; got 1 args' while
the analogous query `sum(avg_over_time(m))` executes successfully.
This fix removes the unnecessary mangling.

Signed-off-by: Anton Tykhyy <atykhyy@gmail.com>
This commit is contained in:
Anton Tykhyy 2023-12-14 12:38:54 +02:00 committed by Aliaksandr Valialkin
parent 1cfa94814b
commit 9f67f62f96
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB

View file

@ -636,10 +636,7 @@ func tryGetArgRollupFuncWithMetricExpr(ae *metricsql.AggrFuncExpr) (*metricsql.F
return nil, nil return nil, nil
} }
// e = rollupFunc(metricExpr) // e = rollupFunc(metricExpr)
return &metricsql.FuncExpr{ return fe, nrf
Name: fe.Name,
Args: []metricsql.Expr{me},
}, nrf
} }
if re, ok := arg.(*metricsql.RollupExpr); ok { if re, ok := arg.(*metricsql.RollupExpr); ok {
if me, ok := re.Expr.(*metricsql.MetricExpr); !ok || me.IsEmpty() || re.ForSubquery() { if me, ok := re.Expr.(*metricsql.MetricExpr); !ok || me.IsEmpty() || re.ForSubquery() {