From 345a7abea2cf18d7ba255dc881390a42fe58878b Mon Sep 17 00:00:00 2001 From: Jesus Vazquez Date: Thu, 20 Jun 2024 13:06:59 +0200 Subject: [PATCH] progress --- promql/parser/lex.go | 4 ++ promql/parser/printer_test.go | 119 +--------------------------------- 2 files changed, 5 insertions(+), 118 deletions(-) diff --git a/promql/parser/lex.go b/promql/parser/lex.go index cf5719c860..df91d7bd2b 100644 --- a/promql/parser/lex.go +++ b/promql/parser/lex.go @@ -471,6 +471,10 @@ func lexStatements(l *Lexer) stateFn { skipSpaces(l) } l.bracketOpen = true + if l.peek() == '^' { + l.emit(POW) + l.next() + } return lexDuration case r == ']': if !l.bracketOpen { diff --git a/promql/parser/printer_test.go b/promql/parser/printer_test.go index f224d841d0..3cc5ae7030 100644 --- a/promql/parser/printer_test.go +++ b/promql/parser/printer_test.go @@ -29,124 +29,7 @@ func TestExprString(t *testing.T) { in, out string }{ { - in: `sum by() (task:errors:rate10s{job="s"})`, - out: `sum(task:errors:rate10s{job="s"})`, - }, - { - in: `sum by(code) (task:errors:rate10s{job="s"})`, - out: `sum by (code) (task:errors:rate10s{job="s"})`, - }, - { - in: `sum without() (task:errors:rate10s{job="s"})`, - out: `sum without () (task:errors:rate10s{job="s"})`, - }, - { - in: `sum without(instance) (task:errors:rate10s{job="s"})`, - out: `sum without (instance) (task:errors:rate10s{job="s"})`, - }, - { - in: `topk(5, task:errors:rate10s{job="s"})`, - }, - { - in: `count_values("value", task:errors:rate10s{job="s"})`, - }, - { - in: `a - on() c`, - out: `a - on () c`, - }, - { - in: `a - on(b) c`, - out: `a - on (b) c`, - }, - { - in: `a - on(b) group_left(x) c`, - out: `a - on (b) group_left (x) c`, - }, - { - in: `a - on(b) group_left(x, y) c`, - out: `a - on (b) group_left (x, y) c`, - }, - { - in: `a - on(b) group_left c`, - out: `a - on (b) group_left () c`, - }, - { - in: `a - on(b) group_left() (c)`, - out: `a - on (b) group_left () (c)`, - }, - { - in: `a - ignoring(b) c`, - out: `a - ignoring (b) c`, - }, - { - in: `a - ignoring() c`, - out: `a - c`, - }, - { - in: `up > bool 0`, - }, - { - in: `a offset 1m`, - }, - { - in: `a offset -7m`, - }, - { - in: `a{c="d"}[5m] offset 1m`, - }, - { - in: `a[5m] offset 1m`, - }, - { - in: `a[12m] offset -3m`, - }, - { - in: `a[1h:5m] offset 1m`, - }, - { - in: `{__name__="a"}`, - }, - { - in: `a{b!="c"}[1m]`, - }, - { - in: `a{b=~"c"}[1m]`, - }, - { - in: `a{b!~"c"}[1m]`, - }, - { - in: `a @ 10`, - out: `a @ 10.000`, - }, - { - in: `a[1m] @ 10`, - out: `a[1m] @ 10.000`, - }, - { - in: `a @ start()`, - }, - { - in: `a @ end()`, - }, - { - in: `a[1m] @ start()`, - }, - { - in: `a[1m] @ end()`, - }, - { - in: `{__name__="",a="x"}`, - }, - { - in: `{"a.b"="c"}`, - }, - { - in: `{"0"="1"}`, - }, - { - in: `{"_0"="1"}`, - out: `{_0="1"}`, + in: `a[^1m]`, }, }