Skip to content

Commit

Permalink
[refactor](Nereids) refactor the parsing way of date series functions
Browse files Browse the repository at this point in the history
  • Loading branch information
morrySnow committed Dec 27, 2024
1 parent 6cfe60f commit 7617f0b
Show file tree
Hide file tree
Showing 9 changed files with 1,065 additions and 363 deletions.
15 changes: 0 additions & 15 deletions fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ ACCOUNT_LOCK: 'ACCOUNT_LOCK';
ACCOUNT_UNLOCK: 'ACCOUNT_UNLOCK';
ACTIONS: 'ACTIONS';
ADD: 'ADD';
ADDDATE:'ADDDATE';
ADMIN: 'ADMIN';
AFTER: 'AFTER';
AGG_STATE: 'AGG_STATE';
Expand All @@ -94,7 +93,6 @@ AND: 'AND';
ANTI: 'ANTI';
APPEND: 'APPEND';
ARRAY: 'ARRAY';
ARRAY_RANGE: 'ARRAY_RANGE';
AS: 'AS';
ASC: 'ASC';
AT: 'AT';
Expand Down Expand Up @@ -181,21 +179,12 @@ DATA: 'DATA';
DATABASE: 'DATABASE';
DATABASES: 'DATABASES';
DATE: 'DATE';
DATE_ADD: 'DATE_ADD';
DATE_CEIL: 'DATE_CEIL';
DATE_DIFF: 'DATE_DIFF';
DATE_FLOOR: 'DATE_FLOOR';
DATE_SUB: 'DATE_SUB';
DATEADD: 'DATEADD';
DATEDIFF: 'DATEDIFF';
DATETIME: 'DATETIME';
DATETIMEV2: 'DATETIMEV2';
DATEV2: 'DATEV2';
DATETIMEV1: 'DATETIMEV1';
DATEV1: 'DATEV1';
DAY: 'DAY';
DAYS_ADD: 'DAYS_ADD';
DAYS_SUB: 'DAYS_SUB';
DECIMAL: 'DECIMAL';
DECIMALV2: 'DECIMALV2';
DECIMALV3: 'DECIMALV3';
Expand Down Expand Up @@ -478,7 +467,6 @@ SCHEMAS: 'SCHEMAS';
SECOND: 'SECOND';
SELECT: 'SELECT';
SEMI: 'SEMI';
SEQUENCE: 'SEQUENCE';
SERIALIZABLE: 'SERIALIZABLE';
SESSION: 'SESSION';
SESSION_USER: 'SESSION_USER';
Expand Down Expand Up @@ -507,7 +495,6 @@ STREAM: 'STREAM';
STREAMING: 'STREAMING';
STRING: 'STRING';
STRUCT: 'STRUCT';
SUBDATE: 'SUBDATE';
SUM: 'SUM';
SUPERUSER: 'SUPERUSER';
SWITCH: 'SWITCH';
Expand All @@ -527,8 +514,6 @@ THAN: 'THAN';
THEN: 'THEN';
TIME: 'TIME';
TIMESTAMP: 'TIMESTAMP';
TIMESTAMPADD: 'TIMESTAMPADD';
TIMESTAMPDIFF: 'TIMESTAMPDIFF';
TINYINT: 'TINYINT';
TO: 'TO';
TRANSACTION: 'TRANSACTION';
Expand Down
68 changes: 2 additions & 66 deletions fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ fixedPartitionDef
;

stepPartitionDef
: FROM from=partitionValueList TO to=partitionValueList INTERVAL unitsAmount=INTEGER_VALUE unit=datetimeUnit?
: FROM from=partitionValueList TO to=partitionValueList INTERVAL unitsAmount=INTEGER_VALUE unit=unitIdentifier?
;

inPartitionDef
Expand Down Expand Up @@ -1507,57 +1507,8 @@ valueExpression
| left=valueExpression comparisonOperator right=valueExpression #comparison
;

datetimeUnit
:YEAR | MONTH | QUARTER | WEEK | DAY | HOUR | MINUTE | SECOND
;

primaryExpression
: operator=(BITAND | BITOR | BITXOR) LEFT_PAREN left = valueExpression
COMMA right = valueExpression RIGHT_PAREN #bitOperation
| name=(TIMESTAMPDIFF | DATEDIFF)
LEFT_PAREN
unit=datetimeUnit COMMA
startTimestamp=valueExpression COMMA
endTimestamp=valueExpression
RIGHT_PAREN #timestampdiff
| name=(TIMESTAMPADD | DATEADD)
LEFT_PAREN
unit=datetimeUnit COMMA
startTimestamp=valueExpression COMMA
endTimestamp=valueExpression
RIGHT_PAREN #timestampadd
| name =(ADDDATE | DAYS_ADD | DATE_ADD)
LEFT_PAREN
timestamp=valueExpression COMMA
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #date_add
| name=(SUBDATE | DAYS_SUB | DATE_SUB)
LEFT_PAREN
timestamp=valueExpression COMMA
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #date_sub
| name=DATE_FLOOR
LEFT_PAREN
timestamp=valueExpression COMMA
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #dateFloor
| name=DATE_CEIL
LEFT_PAREN
timestamp=valueExpression COMMA
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #dateCeil
| name =(ARRAY_RANGE | SEQUENCE)
LEFT_PAREN
start=valueExpression COMMA
end=valueExpression COMMA
(INTERVAL unitsAmount=valueExpression unit=datetimeUnit
| unitsAmount=valueExpression)
RIGHT_PAREN #arrayRange
| name=CURRENT_DATE #currentDate
: name=CURRENT_DATE #currentDate
| name=CURRENT_TIME #currentTime
| name=CURRENT_TIMESTAMP #currentTimestamp
| name=LOCALTIME #localTime
Expand Down Expand Up @@ -1821,15 +1772,13 @@ number
nonReserved
//--DEFAULT-NON-RESERVED-START
: ACTIONS
| ADDDATE
| AFTER
| AGG_STATE
| AGGREGATE
| ALIAS
| ALWAYS
| ANALYZED
| ARRAY
| ARRAY_RANGE
| AT
| AUTHORS
| AUTO_INCREMENT
Expand Down Expand Up @@ -1894,21 +1843,12 @@ nonReserved
| CURRENT_USER
| DATA
| DATE
| DATE_ADD
| DATE_CEIL
| DATE_DIFF
| DATE_FLOOR
| DATE_SUB
| DATEADD
| DATEDIFF
| DATETIME
| DATETIMEV1
| DATETIMEV2
| DATEV1
| DATEV2
| DAY
| DAYS_ADD
| DAYS_SUB
| DECIMAL
| DECIMALV2
| DECIMALV3
Expand Down Expand Up @@ -2091,7 +2031,6 @@ nonReserved
| SECOND
| SERIALIZABLE
| SET_SESSION_VARIABLE
| SEQUENCE
| SESSION
| SESSION_USER
| SHAPE
Expand All @@ -2112,7 +2051,6 @@ nonReserved
| STREAMING
| STRING
| STRUCT
| SUBDATE
| SUM
| TABLES
| TASK
Expand All @@ -2122,8 +2060,6 @@ nonReserved
| THAN
| TIME
| TIMESTAMP
| TIMESTAMPADD
| TIMESTAMPDIFF
| TRANSACTION
| TREE
| TRIGGERS
Expand Down
Loading

0 comments on commit 7617f0b

Please sign in to comment.