forked from opensearch-project/OpenSearch-Dashboards
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Auto Suggest] OpenSearch SQL autosuggest with ANTLR (opensearch-proj…
…ect#7336) * cherry pick Signed-off-by: Eric <menwe@amazon.com> * SQL keyword suggestion Signed-off-by: Eric <menwe@amazon.com> * column and values suggestions Signed-off-by: Eric <menwe@amazon.com> * adjust values suggestions and ignored token Signed-off-by: Eric <menwe@amazon.com> * suggestion type casting Signed-off-by: Eric <menwe@amazon.com> * ignore functions Signed-off-by: Eric <menwe@amazon.com> * case insensitive Signed-off-by: Eric <menwe@amazon.com> * change to use grammar for insensitive case Signed-off-by: Eric <menwe@amazon.com> * fix multi-line issue Signed-off-by: Eric <menwe@amazon.com> * code cleanup Signed-off-by: Eric <menwe@amazon.com> * move ppl out of scope Signed-off-by: Eric <menwe@amazon.com> * rename folder and add ignoring rules Signed-off-by: Eric <menwe@amazon.com> * resolve type issue Signed-off-by: Eric <menwe@amazon.com> * fix ppl suggestion provider issue Signed-off-by: Eric <menwe@amazon.com> * remove function suggestion Signed-off-by: Eric <menwe@amazon.com> * some code clean up and adding tests Signed-off-by: Eric <menwe@amazon.com> * cursor tests Signed-off-by: Eric <menwe@amazon.com> * remove testing setup Signed-off-by: Eric <menwe@amazon.com> * add changelog Signed-off-by: Eric <menwe@amazon.com> * update yarn file Signed-off-by: Eric <menwe@amazon.com> * add missing testing library Signed-off-by: Eric <menwe@amazon.com> * MDS integration Signed-off-by: Eric <menwe@amazon.com> * minor interface change and disable word based suggestion Signed-off-by: Eric <menwe@amazon.com> * update ID_LITERAL and recompile grammar Signed-off-by: Eric <menwe@amazon.com> * column suggest for agg function Signed-off-by: Eric <menwe@amazon.com> * revert version Signed-off-by: Eric <menwe@amazon.com> * opensearch sql syntax highlighting Signed-off-by: Eric <menwe@amazon.com> * add utility tests Signed-off-by: Eric <menwe@amazon.com> * symbol table test Signed-off-by: Eric <menwe@amazon.com> * error listener test Signed-off-by: Eric <menwe@amazon.com> * parse test Signed-off-by: Eric <menwe@amazon.com> * add suggestion provider to single line query editor Signed-off-by: Eric <menwe@amazon.com> * remove one test Signed-off-by: Eric <menwe@amazon.com> * add connection service type Signed-off-by: Eric <menwe@amazon.com> --------- Signed-off-by: Eric <menwe@amazon.com> (cherry picked from commit 9348bd4)
- Loading branch information
1 parent
0203b20
commit fea5f44
Showing
52 changed files
with
43,710 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
feat: | ||
- [Auto Suggest] OpenSearch SQL autosuggest with ANTLR ([#7336](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7336)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
packages/osd-monaco/src/xjson/lexer_rules/opensearchsql.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { monaco } from '../../monaco'; | ||
|
||
export const ID = 'SQL'; | ||
|
||
const keywords = [ | ||
'ALL', | ||
'AND', | ||
'AS', | ||
'ASC', | ||
'BOOLEAN', | ||
'BETWEEN', | ||
'BY', | ||
'CASE', | ||
'CAST', | ||
'CROSS', | ||
'COLUMNS', | ||
'DATETIME', | ||
'DELETE', | ||
'DESC', | ||
'DESCRIBE', | ||
'DISTINCT', | ||
'DOUBLE', | ||
'ELSE', | ||
'EXISTS', | ||
'FALSE', | ||
'FLOAT', | ||
'FIRST', | ||
'FROM', | ||
'GROUP', | ||
'HAVING', | ||
'IN', | ||
'INNER', | ||
'INT', | ||
'INTEGER', | ||
'IS', | ||
'JOIN', | ||
'LAST', | ||
'LEFT', | ||
'LIKE', | ||
'LIMIT', | ||
'LONG', | ||
'MATCH', | ||
'NATURAL', | ||
'NOT', | ||
'NULL', | ||
'NULLS', | ||
'ON', | ||
'OR', | ||
'ORDER', | ||
'OUTER', | ||
'OVER', | ||
'PARTITION', | ||
'REGEXP', | ||
'RIGHT', | ||
'SELECT', | ||
'SHOW', | ||
'STRING', | ||
'THEN', | ||
'TRUE', | ||
'UNION', | ||
'USING', | ||
'WHEN', | ||
'WHERE', | ||
'EXCEPT', | ||
]; | ||
|
||
const functions = [ | ||
'AVG', | ||
'COUNT', | ||
'MAX', | ||
'MIN', | ||
'SUM', | ||
'VAR_POP', | ||
'VAR_SAMP', | ||
'VARIANCE', | ||
'STD', | ||
'STDDEV', | ||
'STDDEV_POP', | ||
'STDDEV_SAMP', | ||
'SUBSTRING', | ||
'TRIM', | ||
]; | ||
|
||
const operators = [ | ||
'=', | ||
'>', | ||
'<', | ||
'!', | ||
'~', | ||
'\\|', | ||
'&', | ||
'\\^', | ||
'\\*', | ||
'/', | ||
'%', | ||
'\\+', | ||
'-', | ||
'DIV', | ||
'MOD', | ||
]; | ||
|
||
const brackets = [ | ||
{ open: '(', close: ')', token: 'delimiter.parenthesis' }, | ||
{ open: '[', close: ']', token: 'delimiter.square' }, | ||
]; | ||
|
||
export const lexerRules = { | ||
defaultToken: 'invalid', | ||
ignoreCase: true, | ||
tokenPostfix: '', | ||
keywords, | ||
functions, | ||
operators, | ||
brackets, | ||
tokenizer: { | ||
root: [ | ||
[ | ||
/[a-zA-Z_$][a-zA-Z0-9_$]*/, | ||
{ | ||
cases: { | ||
'@keywords': 'keyword', | ||
'@functions': 'function', | ||
'@default': 'identifier', | ||
}, | ||
}, | ||
], | ||
{ include: '@whitespace' }, | ||
[/[()]/, '@brackets'], | ||
[new RegExp(operators.join('|')), 'operator'], | ||
[/[0-9]+(\.[0-9]+)?/, 'number'], | ||
[/'([^'\\]|\\.)*$/, 'string.invalid'], // non-terminated string | ||
[/'/, 'string', '@string'], | ||
[/"/, 'string', '@string'], | ||
], | ||
whitespace: [ | ||
[/[ \t\r\n]+/, 'white'], | ||
[/\/\*/, 'comment', '@comment'], | ||
[/--.*$/, 'comment'], | ||
], | ||
string: [ | ||
[/[^'\\]+/, 'string'], | ||
[/\\./, 'string.escape'], | ||
[/'/, 'string', '@pop'], | ||
[/"/, 'string', '@pop'], | ||
], | ||
comment: [ | ||
[/[^/*]+/, 'comment'], | ||
[/\*\//, 'comment', '@pop'], | ||
[/[\/*]/, 'comment'], | ||
], | ||
}, | ||
} as monaco.languages.IMonarchLanguage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.