app/vmselect/promql: properly handle -n^m like Prometheus does

`-n^m` must be handled as `-(n^m)` instead of `(-n)^m`.

See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/675
This commit is contained in:
Aliaksandr Valialkin 2020-08-07 07:38:18 +03:00
parent 7f93d61a56
commit 95a8c492ef
5 changed files with 19 additions and 9 deletions

View file

@ -868,12 +868,23 @@ func TestExecSuccess(t *testing.T) {
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run("time()*-1^0.5", func(t *testing.T) {
t.Run("time()*(-4)^0.5", func(t *testing.T) {
t.Parallel()
q := `time()*-1^0.5`
q := `time()*(-4)^0.5`
resultExpected := []netstorage.Result{}
f(q, resultExpected)
})
t.Run("time()*-4^0.5", func(t *testing.T) {
t.Parallel()
q := `time()*-4^0.5`
r := netstorage.Result{
MetricName: metricNameExpected,
Values: []float64{-2000, -2400, -2800, -3200, -3600, -4000},
Timestamps: timestampsExpected,
}
resultExpected := []netstorage.Result{r}
f(q, resultExpected)
})
t.Run(`alias()`, func(t *testing.T) {
t.Parallel()
q := `alias(time(), "foobar")`

2
go.mod
View file

@ -8,7 +8,7 @@ require (
// like https://github.com/valyala/fasthttp/commit/996610f021ff45fdc98c2ce7884d5fa4e7f9199b
github.com/VictoriaMetrics/fasthttp v1.0.4
github.com/VictoriaMetrics/metrics v1.12.2
github.com/VictoriaMetrics/metricsql v0.4.0
github.com/VictoriaMetrics/metricsql v0.4.1
github.com/aws/aws-sdk-go v1.33.19
github.com/cespare/xxhash/v2 v2.1.1
github.com/golang/snappy v0.0.1

4
go.sum
View file

@ -51,8 +51,8 @@ github.com/VictoriaMetrics/fasthttp v1.0.4 h1:Aw6UqmPc0v5PunYOpiiyf4hk5B9PTMswdT
github.com/VictoriaMetrics/fasthttp v1.0.4/go.mod h1:m5wCmg1dJN6s1B/lp8/dcKrnnM2l3DWB2eAGZGCTK3g=
github.com/VictoriaMetrics/metrics v1.12.2 h1:SG8iAmqavDNuh7GIdHPoGHUhDL23KeKfvSZSozucNeA=
github.com/VictoriaMetrics/metrics v1.12.2/go.mod h1:Z1tSfPfngDn12bTfZSCqArT3OPY3u88J12hSoOhuiRE=
github.com/VictoriaMetrics/metricsql v0.4.0 h1:1CMGiUzOgR83Y+hVS83/DaHYLaR6PFw1XWcvQnHn2V8=
github.com/VictoriaMetrics/metricsql v0.4.0/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8=
github.com/VictoriaMetrics/metricsql v0.4.1 h1:WbVIfRNCK7HjrzayrpAl07mkh4kiDFZuECsh57rly2Q=
github.com/VictoriaMetrics/metricsql v0.4.1/go.mod h1:ylO7YITho/Iw6P71oEaGyHbO94bGoGtzWfLGqFhMIg8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156 h1:eMwmnE/GDgah4HI848JfFxHt+iPb26b4zyfspmqY0/8=
github.com/allegro/bigcache v1.2.1-0.20190218064605-e24eb225f156/go.mod h1:Cb/ax3seSYIx7SuZdm2G2xzfwmv3TPSk2ucNfQESPXM=
github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=

View file

@ -399,7 +399,7 @@ func (p *parser) parseSingleExprWithoutRollupSuffix() (Expr, error) {
case "{":
return p.parseMetricExpr()
case "-":
// Unary minus. Substitute -expr with (0 - expr)
// Unary minus. Substitute `-expr` with `0 - expr`
if err := p.lex.Next(); err != nil {
return nil, err
}
@ -414,8 +414,7 @@ func (p *parser) parseSingleExprWithoutRollupSuffix() (Expr, error) {
},
Right: e,
}
pe := parensExpr{be}
return &pe, nil
return be, nil
case "+":
// Unary plus
if err := p.lex.Next(); err != nil {

2
vendor/modules.txt vendored
View file

@ -16,7 +16,7 @@ github.com/VictoriaMetrics/fasthttp/fasthttputil
github.com/VictoriaMetrics/fasthttp/stackless
# github.com/VictoriaMetrics/metrics v1.12.2
github.com/VictoriaMetrics/metrics
# github.com/VictoriaMetrics/metricsql v0.4.0
# github.com/VictoriaMetrics/metricsql v0.4.1
github.com/VictoriaMetrics/metricsql
github.com/VictoriaMetrics/metricsql/binaryop
# github.com/aws/aws-sdk-go v1.33.19