Skip to content

Commit

Permalink
feat(query) add grammar support for @modifier. (#1670)
Browse files Browse the repository at this point in the history
* add grammar support for @modifier.

---------

Co-authored-by: Yu Zhang <[email protected]>
  • Loading branch information
yu-shipit and Yu Zhang authored Sep 29, 2023
1 parent bf8ead0 commit b537be9
Show file tree
Hide file tree
Showing 13 changed files with 887 additions and 591 deletions.
12 changes: 10 additions & 2 deletions prometheus/src/main/java/filodb/prometheus/antlr/PromQL.g4
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vectorExpression
| vectorExpression compareOp grouping? vectorExpression #binaryOperation
| vectorExpression andUnlessOp grouping? vectorExpression #binaryOperation
| vectorExpression orOp grouping? vectorExpression #binaryOperation
| vectorExpression subquery offset? #subqueryOperation
| vectorExpression subquery modifier? #subqueryOperation
| vectorExpression limit #limitOperation
| vector #vectorOperation
;
Expand All @@ -44,7 +44,7 @@ vector
parens: '(' vectorExpression ')';

// TODO: Make offset applicable to any expression.
instantOrRangeSelector: instantSelector window? offset?;
instantOrRangeSelector: instantSelector window? modifier?;

instantSelector
: metricName ('{' labelMatcherList? '}')?
Expand All @@ -55,6 +55,10 @@ window: '[' DURATION ']';

offset: OFFSET DURATION;

atModifier: AT(NUMBER | START | END);

modifier: offset | atModifier | offset atModifier | atModifier offset;

limit: LIMIT NUMBER;

subquery: '[' DURATION ':' DURATION? ']';
Expand Down Expand Up @@ -149,6 +153,8 @@ LE: '<=';
RE: '=~';
NRE: '!~';

AT: '@';

// See section below: "Magic for case-insensitive matching."
AND: A N D;
OR: O R;
Expand All @@ -162,6 +168,8 @@ GROUP_RIGHT: G R O U P '_' R I G H T;
OFFSET: O F F S E T;
LIMIT: L I M I T;
BOOL: B O O L;
START: S T A R T '(' ')';
END: E N D '(' ')';

// See section below: "Magic for case-insensitive matching."
AGGREGATION_OP
Expand Down
10 changes: 9 additions & 1 deletion prometheus/src/main/java/filodb/prometheus/antlr/PromQL.interp

Large diffs are not rendered by default.

40 changes: 22 additions & 18 deletions prometheus/src/main/java/filodb/prometheus/antlr/PromQL.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ GE=22
LE=23
RE=24
NRE=25
AND=26
OR=27
UNLESS=28
BY=29
WITHOUT=30
ON=31
IGNORING=32
GROUP_LEFT=33
GROUP_RIGHT=34
OFFSET=35
LIMIT=36
BOOL=37
AGGREGATION_OP=38
DURATION=39
IDENTIFIER=40
IDENTIFIER_EXTENDED=41
WS=42
COMMENT=43
AT=26
AND=27
OR=28
UNLESS=29
BY=30
WITHOUT=31
ON=32
IGNORING=33
GROUP_LEFT=34
GROUP_RIGHT=35
OFFSET=36
LIMIT=37
BOOL=38
START=39
END=40
AGGREGATION_OP=41
DURATION=42
IDENTIFIER=43
IDENTIFIER_EXTENDED=44
WS=45
COMMENT=46
'('=1
')'=2
'{'=3
Expand All @@ -64,3 +67,4 @@ COMMENT=43
'<='=23
'=~'=24
'!~'=25
'@'=26
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Generated from PromQL.g4 by ANTLR 4.9.3
// Generated from PromQL.g4 by ANTLR 4.9.1
package filodb.prometheus.antlr;
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;

Expand Down Expand Up @@ -144,6 +144,20 @@ public class PromQLBaseVisitor<T> extends AbstractParseTreeVisitor<T> implements
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitOffset(PromQLParser.OffsetContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitAtModifier(PromQLParser.AtModifierContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*/
@Override public T visitModifier(PromQLParser.ModifierContext ctx) { return visitChildren(ctx); }
/**
* {@inheritDoc}
*
Expand Down

Large diffs are not rendered by default.

395 changes: 202 additions & 193 deletions prometheus/src/main/java/filodb/prometheus/antlr/PromQLLexer.java

Large diffs are not rendered by default.

40 changes: 22 additions & 18 deletions prometheus/src/main/java/filodb/prometheus/antlr/PromQLLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,27 @@ GE=22
LE=23
RE=24
NRE=25
AND=26
OR=27
UNLESS=28
BY=29
WITHOUT=30
ON=31
IGNORING=32
GROUP_LEFT=33
GROUP_RIGHT=34
OFFSET=35
LIMIT=36
BOOL=37
AGGREGATION_OP=38
DURATION=39
IDENTIFIER=40
IDENTIFIER_EXTENDED=41
WS=42
COMMENT=43
AT=26
AND=27
OR=28
UNLESS=29
BY=30
WITHOUT=31
ON=32
IGNORING=33
GROUP_LEFT=34
GROUP_RIGHT=35
OFFSET=36
LIMIT=37
BOOL=38
START=39
END=40
AGGREGATION_OP=41
DURATION=42
IDENTIFIER=43
IDENTIFIER_EXTENDED=44
WS=45
COMMENT=46
'('=1
')'=2
'{'=3
Expand All @@ -64,3 +67,4 @@ COMMENT=43
'<='=23
'=~'=24
'!~'=25
'@'=26
Loading

0 comments on commit b537be9

Please sign in to comment.