Skip to content

Commit

Permalink
SQL: Allow whitespaces in escape patterns (#47577)
Browse files Browse the repository at this point in the history
Previously, we supported only the format `{fn <FUNCTION_NAME>()}`
but other DBs like MSSQL, DB2, MariaDB/MySQL alos allow whitespaces
between `{` and `fn`. Furhermore, also some applications - like PowerBI -
generate escape sequences with spaces: `select { fn name(params) } etc.`

Add support for white spaces between `{` and the escape pattern definition
like `fn`, `ts`, `d`, `guid` etc.

Closes: #47401

(cherry picked from commit 08a22d0)
  • Loading branch information
matriv committed Oct 7, 2019
1 parent 5575c96 commit c2583e5
Show file tree
Hide file tree
Showing 6 changed files with 561 additions and 557 deletions.
19 changes: 10 additions & 9 deletions x-pack/plugin/sql/src/main/antlr/SqlBase.g4
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pattern

patternEscape
: ESCAPE escape=string
| ESCAPE_ESC escape=string '}'
| ESCAPE_ESC escape=string ESC_END
;

valueExpression
Expand Down Expand Up @@ -255,7 +255,7 @@ extractTemplate

functionExpression
: functionTemplate
| FUNCTION_ESC functionTemplate '}'
| FUNCTION_ESC functionTemplate ESC_END
;

functionTemplate
Expand Down Expand Up @@ -446,15 +446,16 @@ YEAR: 'YEAR';
YEARS: 'YEARS';

// Escaped Sequence
ESCAPE_ESC: '{ESCAPE';
FUNCTION_ESC: '{FN';
LIMIT_ESC:'{LIMIT';
DATE_ESC: '{D';
TIME_ESC: '{T';
TIMESTAMP_ESC: '{TS';
ESCAPE_ESC: ESC_START 'ESCAPE';
FUNCTION_ESC: ESC_START 'FN';
LIMIT_ESC: ESC_START 'LIMIT';
DATE_ESC: ESC_START 'D';
TIME_ESC: ESC_START 'T';
TIMESTAMP_ESC: ESC_START 'TS';
// mapped to string literal
GUID_ESC: '{GUID';
GUID_ESC: ESC_START 'GUID';

ESC_START: '{' (WS)*;
ESC_END: '}';

EQ : '=';
Expand Down
96 changes: 45 additions & 51 deletions x-pack/plugin/sql/src/main/antlr/SqlBase.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -96,35 +96,36 @@ DATE_ESC=95
TIME_ESC=96
TIMESTAMP_ESC=97
GUID_ESC=98
ESC_END=99
EQ=100
NULLEQ=101
NEQ=102
LT=103
LTE=104
GT=105
GTE=106
PLUS=107
MINUS=108
ASTERISK=109
SLASH=110
PERCENT=111
CONCAT=112
DOT=113
PARAM=114
STRING=115
INTEGER_VALUE=116
DECIMAL_VALUE=117
IDENTIFIER=118
DIGIT_IDENTIFIER=119
TABLE_IDENTIFIER=120
QUOTED_IDENTIFIER=121
BACKQUOTED_IDENTIFIER=122
SIMPLE_COMMENT=123
BRACKETED_COMMENT=124
WS=125
UNRECOGNIZED=126
DELIMITER=127
ESC_START=99
ESC_END=100
EQ=101
NULLEQ=102
NEQ=103
LT=104
LTE=105
GT=106
GTE=107
PLUS=108
MINUS=109
ASTERISK=110
SLASH=111
PERCENT=112
CONCAT=113
DOT=114
PARAM=115
STRING=116
INTEGER_VALUE=117
DECIMAL_VALUE=118
IDENTIFIER=119
DIGIT_IDENTIFIER=120
TABLE_IDENTIFIER=121
QUOTED_IDENTIFIER=122
BACKQUOTED_IDENTIFIER=123
SIMPLE_COMMENT=124
BRACKETED_COMMENT=125
WS=126
UNRECOGNIZED=127
DELIMITER=128
'('=1
')'=2
','=3
Expand Down Expand Up @@ -216,25 +217,18 @@ DELIMITER=127
'WITH'=89
'YEAR'=90
'YEARS'=91
'{ESCAPE'=92
'{FN'=93
'{LIMIT'=94
'{D'=95
'{T'=96
'{TS'=97
'{GUID'=98
'}'=99
'='=100
'<=>'=101
'<'=103
'<='=104
'>'=105
'>='=106
'+'=107
'-'=108
'*'=109
'/'=110
'%'=111
'||'=112
'.'=113
'?'=114
'}'=100
'='=101
'<=>'=102
'<'=104
'<='=105
'>'=106
'>='=107
'+'=108
'-'=109
'*'=110
'/'=111
'%'=112
'||'=113
'.'=114
'?'=115
94 changes: 44 additions & 50 deletions x-pack/plugin/sql/src/main/antlr/SqlBaseLexer.tokens
Original file line number Diff line number Diff line change
Expand Up @@ -96,34 +96,35 @@ DATE_ESC=95
TIME_ESC=96
TIMESTAMP_ESC=97
GUID_ESC=98
ESC_END=99
EQ=100
NULLEQ=101
NEQ=102
LT=103
LTE=104
GT=105
GTE=106
PLUS=107
MINUS=108
ASTERISK=109
SLASH=110
PERCENT=111
CONCAT=112
DOT=113
PARAM=114
STRING=115
INTEGER_VALUE=116
DECIMAL_VALUE=117
IDENTIFIER=118
DIGIT_IDENTIFIER=119
TABLE_IDENTIFIER=120
QUOTED_IDENTIFIER=121
BACKQUOTED_IDENTIFIER=122
SIMPLE_COMMENT=123
BRACKETED_COMMENT=124
WS=125
UNRECOGNIZED=126
ESC_START=99
ESC_END=100
EQ=101
NULLEQ=102
NEQ=103
LT=104
LTE=105
GT=106
GTE=107
PLUS=108
MINUS=109
ASTERISK=110
SLASH=111
PERCENT=112
CONCAT=113
DOT=114
PARAM=115
STRING=116
INTEGER_VALUE=117
DECIMAL_VALUE=118
IDENTIFIER=119
DIGIT_IDENTIFIER=120
TABLE_IDENTIFIER=121
QUOTED_IDENTIFIER=122
BACKQUOTED_IDENTIFIER=123
SIMPLE_COMMENT=124
BRACKETED_COMMENT=125
WS=126
UNRECOGNIZED=127
'('=1
')'=2
','=3
Expand Down Expand Up @@ -215,25 +216,18 @@ UNRECOGNIZED=126
'WITH'=89
'YEAR'=90
'YEARS'=91
'{ESCAPE'=92
'{FN'=93
'{LIMIT'=94
'{D'=95
'{T'=96
'{TS'=97
'{GUID'=98
'}'=99
'='=100
'<=>'=101
'<'=103
'<='=104
'>'=105
'>='=106
'+'=107
'-'=108
'*'=109
'/'=110
'%'=111
'||'=112
'.'=113
'?'=114
'}'=100
'='=101
'<=>'=102
'<'=104
'<='=105
'>'=106
'>='=107
'+'=108
'-'=109
'*'=110
'/'=111
'%'=112
'||'=113
'.'=114
'?'=115
Loading

0 comments on commit c2583e5

Please sign in to comment.