Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add _all_ date function aliases to parser (extended) #1982

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
69 changes: 61 additions & 8 deletions src/alasqlparser.jison
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TEXT\s+OF\s+SELECT yytext = 'TEXT';return 'SELECT'
'ABSOLUTE' return 'ABSOLUTE'
'ACTION' return 'ACTION'
'ADD' return 'ADD'
'ADDDATE' return 'DATE_ADD'
'AFTER' return 'AFTER'
'AGGR' return 'AGGR'
'AGGREGATE' return 'AGGREGATE'
Expand Down Expand Up @@ -104,13 +105,21 @@ COLUMNS return 'COLUMN'
"CROSS" return 'CROSS'
'CUBE' return 'CUBE'
"CURRENT_TIMESTAMP" return 'CURRENT_TIMESTAMP'
"GETDATE" return 'CURRENT_TIMESTAMP'
"NOW" return 'CURRENT_TIMESTAMP'
"CURRENT_DATE" return 'CURRENT_DATE'
"CURDATE" return 'CURRENT_DATE'
"CURSOR" return 'CURSOR'
DATABASE(S)? return 'DATABASE'
'DAY' return 'DAY'
'DAYOFMONTH' return 'DAY'
mathiasrw marked this conversation as resolved.
Show resolved Hide resolved
'DAYOFYEAR' return 'DAY'
paulrutter marked this conversation as resolved.
Show resolved Hide resolved
'DATEADD' return 'DATEADD'
'DATEDIFF' return 'DATEDIFF'
'TIMESTAMPDIFF' return 'TIMESTAMPDIFF'
'DAYOFWEEK' return 'DAYOFWEEK'
'DATE_ADD' return 'DATE_ADD'
'DATE_SUB' return 'DATE_SUB'
'TIMESTAMPDIFF' return 'TIMESTAMPDIFF'
'DECLARE' return 'DECLARE'
'DEFAULT' return 'DEFAULT'
'DELETE' return 'DELETE'
Expand Down Expand Up @@ -145,6 +154,7 @@ DATABASE(S)? return 'DATABASE'
'GROUP' return 'GROUP'
'GROUPING' return 'GROUPING'
'HAVING' return 'HAVING'
'HOUR' return 'HOUR'
/*'HELP' return 'HELP'*/
'IF' return 'IF'
'IDENTITY' return 'IDENTITY'
Expand Down Expand Up @@ -178,7 +188,11 @@ DATABASE(S)? return 'DATABASE'

"MERGE" return 'MERGE'
"MINUS" return 'EXCEPT'
"MINUTE" return 'MINUTE'
'MILLISECOND' return 'MILLISECOND'
'MICROSECOND' return 'MICROSECOND'
"MODIFY" return 'MODIFY'
'MONTH' return 'MONTH'
'NATURAL' return 'NATURAL'
'NEXT' return 'NEXT'
'NEW' return 'NEW'
Expand Down Expand Up @@ -207,6 +221,7 @@ DATABASE(S)? return 'DATABASE'
'PRINT' return 'PRINT'
'PRIOR' return 'PRIOR'
'QUERY' return 'QUERY'
'QUARTER' return 'QUARTER'
'READ' return 'READ'
'RECORDSET' return 'RECORDSET'
'REDUCE' return 'REDUCE'
Expand All @@ -229,6 +244,7 @@ DATABASE(S)? return 'DATABASE'
'ROWS' return 'ROWS'
SCHEMA(S)? return 'DATABASE'
'SEARCH' return 'SEARCH'
'SECOND' return 'SECOND'

'SEMI' return 'SEMI'
SET return 'SET'
Expand All @@ -238,6 +254,7 @@ SETS return 'SET'
'SOURCE' return 'SOURCE'
'STRATEGY' return 'STRATEGY'
'STORE' return 'STORE'
'SUBDATE' return 'DATE_SUB'
'SUM' return 'SUM'
'TOTAL' return 'TOTAL'
'TABLE' return 'TABLE'
Expand Down Expand Up @@ -270,7 +287,10 @@ SETS return 'SET'
'WHERE' return 'WHERE'
'WHILE' return 'WHILE'
'WITH' return 'WITH'
'WEEK' return 'WEEK'
'WEEKDAY' return 'DAYOFWEEK'
'WORK' return 'TRANSACTION' /* Is this keyword required? */
'YEAR' return 'YEAR'

(\d*[.])?\d+[eE]\d+ return 'NUMBER'
(\d*[.])?\d+ return 'NUMBER'
Expand Down Expand Up @@ -589,6 +609,21 @@ ArrowDot
| DOT
;

IntervalLiteral
: MICROSECOND
| MILLISECOND
| SECOND
| MINUTE
| HOUR
| DAY
| DAYOFWEEK
paulrutter marked this conversation as resolved.
Show resolved Hide resolved
| DAYOFYEAR
mathiasrw marked this conversation as resolved.
Show resolved Hide resolved
| WEEK
| MONTH
| QUARTER
| YEAR
;

SearchSelector
: Literal
{ $$ = {srchid:"PROP", args: [$1]}; }
Expand Down Expand Up @@ -1394,18 +1429,36 @@ FuncValue
{ $$ = new yy.FuncValue({ funcid: 'REPLACE', args:$3 }) }
| CURRENT_DATE LPAR RPAR
{ $$ = new yy.FuncValue({ funcid: $1 }) }
| DATEADD LPAR Literal COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEADD', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| CURRENT_TIMESTAMP LPAR RPAR
{ $$ = new yy.FuncValue({ funcid: $1 }) }
| DATEADD LPAR STRING COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEADD', args:[$3,$5,$7]}) }
| DATEDIFF LPAR Literal COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEDIFF', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| DATEADD LPAR IntervalLiteral COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEADD', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| DATEDIFF LPAR STRING COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEDIFF', args:[$3,$5,$7]}) }
| DATEDIFF LPAR IntervalLiteral COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'DATEDIFF', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| DATE_ADD LPAR Expression COMMA Expression RPAR
/* e.g. DATE_ADD(NOW(), 24 * 3600 * 1000) */
{ $$ = new yy.FuncValue({ funcid: 'DATE_ADD', args:[$3, $5] }) }
| DATE_ADD LPAR Expression COMMA INTERVAL Expression IntervalLiteral RPAR
/* e.g. DATE_ADD(NOW(), INTERVAL 10 day) */
{ $$ = new yy.FuncValue({ funcid: 'DATE_ADD', args:[$3, new yy.FuncValue({ funcid: 'INTERVAL', args:[$6,new yy.StringValue({value:($7).toLowerCase()})]})] }) }
| DATE_SUB LPAR Expression COMMA Expression RPAR
/* e.g. DATE_SUB(NOW(), 24 * 3600 * 1000) */
{ $$ = new yy.FuncValue({ funcid: 'DATE_SUB', args:[$3, $5]}) }
| DATE_SUB LPAR Expression COMMA INTERVAL Expression IntervalLiteral RPAR
/* e.g. DATE_SUB(NOW(), INTERVAL 10 day) */
{ $$ = new yy.FuncValue({ funcid: 'DATE_SUB', args:[$3, new yy.FuncValue({ funcid: 'INTERVAL', args:[$6,new yy.StringValue({value:($7).toLowerCase()})]}) ]}) }
| (YEAR|MONTH|DAY|DAYOFWEEK|HOUR|MINUTE|SECOND) LPAR Expression RPAR
paulrutter marked this conversation as resolved.
Show resolved Hide resolved
{ $$ = new yy.FuncValue({ funcid: $1, args: [$3] }) }
| TIMESTAMPDIFF LPAR Expression COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'TIMESTAMPDIFF', args:[new yy.StringValue({value:$3}),$5,$7]}) }
| INTERVAL Expression Literal
{ $$ = new yy.FuncValue({ funcid: 'INTERVAL', args:[$2,new yy.StringValue({value:($3).toLowerCase()})]}); }
{ $$ = new yy.FuncValue({ funcid: 'TIMESTAMPDIFF', args: [new yy.StringValue({value:$3}),$5,$7]}) }
| TIMESTAMPDIFF LPAR IntervalLiteral COMMA Expression COMMA Expression RPAR
{ $$ = new yy.FuncValue({ funcid: 'TIMESTAMPDIFF', args: [new yy.StringValue({value:$3}),$5,$7]}) }
| INTERVAL Expression IntervalLiteral
{ $$ = new yy.FuncValue({ funcid: 'INTERVAL', args: [$2,new yy.StringValue({value:($3).toLowerCase()})]}); }
;

ExprList
Expand Down
Loading
Loading