-
Notifications
You must be signed in to change notification settings - Fork 920
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
[Auto Suggest] OpenSearch SQL autosuggest with ANTLR #7336
Merged
mengweieric
merged 39 commits into
opensearch-project:main
from
mengweieric:feature/antlr-autocomplete
Jul 23, 2024
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
df0a054
cherry pick
mengweieric e5175af
SQL keyword suggestion
mengweieric d5daf39
column and values suggestions
mengweieric f0de90e
adjust values suggestions and ignored token
mengweieric be42ea2
suggestion type casting
mengweieric f215024
ignore functions
mengweieric 2a452e9
case insensitive
mengweieric 7ae59f4
change to use grammar for insensitive case
mengweieric 64c266d
fix multi-line issue
mengweieric 7c62bf7
code cleanup
mengweieric c9da113
move ppl out of scope
mengweieric 140114a
rename folder and add ignoring rules
mengweieric f1014b7
resolve type issue
mengweieric 152a645
fix ppl suggestion provider issue
mengweieric 79e7782
remove function suggestion
mengweieric 4d84d3b
some code clean up and adding tests
mengweieric 609a2a9
sync main and resolve conflicts
mengweieric ce01e2c
cursor tests
mengweieric d7e3bd4
remove testing setup
mengweieric 3aa0dff
add changelog
mengweieric d1e2540
update yarn file
mengweieric a5d12e5
add missing testing library
mengweieric a606aa8
MDS integration
mengweieric 12715a2
Merge branch 'main' into feature/antlr-autocomplete
mengweieric 4a8300b
minor interface change and disable word based suggestion
mengweieric 9cb77b8
update ID_LITERAL and recompile grammar
mengweieric 7851dc3
column suggest for agg function
mengweieric 8ccd18e
Merge branch 'main' into feature/antlr-autocomplete
mengweieric e0b5082
revert version
mengweieric 1102148
opensearch sql syntax highlighting
mengweieric 799c903
Merge branch 'main' into feature/antlr-autocomplete
mengweieric 878beb9
add utility tests
mengweieric fae7267
symbol table test
mengweieric f9b7717
error listener test
mengweieric 9009922
parse test
mengweieric f28f558
add suggestion provider to single line query editor
mengweieric 1f9080b
remove one test
mengweieric 2fa1dfb
add connection service type
mengweieric 3e5b430
Merge branch 'main' into feature/antlr-autocomplete
mengweieric File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,7 +84,8 @@ | |
"cypress:run-without-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=false", | ||
"cypress:run-with-security": "env TZ=America/Los_Angeles NO_COLOR=1 cypress run --headless --env SECURITY_ENABLED=true,openSearchUrl=https://localhost:9200,WAIT_FOR_LOADER_BUFFER_MS=500", | ||
"osd:ciGroup10": "echo \"dashboard_sanity_test_spec.js\"", | ||
"osd:ciGroup11": "echo \"apps/vis_builder/*.js\"" | ||
"osd:ciGroup11": "echo \"apps/vis_builder/*.js\"", | ||
"generate:opensearchsqlantlr": "./node_modules/antlr4ng-cli/index.js -Dlanguage=TypeScript -o ./src/plugins/data/public/antlr/opensearch_sql/.generated -visitor -no-listener -Xexact-output-dir ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLLexer.g4 ./src/plugins/data/public/antlr/opensearch_sql/grammar/OpenSearchSQLParser.g4" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
@@ -114,7 +115,7 @@ | |
"**/nth-check": "^2.0.1", | ||
"**/semver": "^7.5.3", | ||
"**/set-value": "^4.1.0", | ||
"**/tar":"^6.2.1", | ||
"**/tar": "^6.2.1", | ||
"**/topo/hoek": "npm:@amoo-miki/[email protected]", | ||
"**/trim": "^0.0.3", | ||
"**/typescript": "4.6.4", | ||
|
@@ -179,6 +180,8 @@ | |
"JSONStream": "1.3.5", | ||
"abortcontroller-polyfill": "^1.4.0", | ||
"ajv": "^8.11.0", | ||
"antlr4-c3": "^3.4.1", | ||
"antlr4ng": "^3.0.4", | ||
"bluebird": "3.5.5", | ||
"chalk": "^4.1.0", | ||
"chokidar": "^3.4.2", | ||
|
@@ -245,11 +248,11 @@ | |
"whatwg-fetch": "^3.0.0", | ||
"yauzl": "^2.10.0", | ||
"@opensearch-dashboards-test/opensearch-dashboards-test-library": "https://github.com/opensearch-project/opensearch-dashboards-test-library/archive/refs/tags/1.0.6.tar.gz" | ||
|
||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.22.9", | ||
"@babel/parser": "^7.22.9", | ||
"@babel/plugin-transform-class-static-block": "^7.24.4", | ||
"@babel/register": "^7.22.9", | ||
"@babel/types": "^7.22.9", | ||
"@elastic/apm-rum": "^5.6.1", | ||
|
@@ -364,6 +367,7 @@ | |
"@types/zen-observable": "^0.8.0", | ||
"@typescript-eslint/eslint-plugin": "^3.10.0", | ||
"@typescript-eslint/parser": "^3.10.0", | ||
"antlr4ng-cli": "^2.0.0", | ||
"archiver": "^5.3.0", | ||
"axe-core": "^4.0.2", | ||
"babel-eslint": "^10.0.3", | ||
|
@@ -465,6 +469,7 @@ | |
"regenerate": "^1.4.0", | ||
"reselect": "^4.0.0", | ||
"resize-observer-polyfill": "^1.5.1", | ||
"rimraf": "^5.0.7", | ||
"selenium-webdriver": "^4.0.0-alpha.7", | ||
"simple-git": "^3.16.0", | ||
"sinon": "^7.4.2", | ||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are this manual or auto generated? If it is manual, we may need better mechanism in the future to embed this into CI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for now it's manually generated, previously we add this to post commit hook but since the build pipeline does not have java runtime, we switch to manual and only need to run this when there's grammar changes