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

[Auto Suggest] OpenSearch SQL autosuggest with ANTLR #7336

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
df0a054
cherry pick
mengweieric Jun 14, 2024
e5175af
SQL keyword suggestion
mengweieric Jun 17, 2024
d5daf39
column and values suggestions
mengweieric Jun 20, 2024
f0de90e
adjust values suggestions and ignored token
mengweieric Jun 21, 2024
be42ea2
suggestion type casting
mengweieric Jun 24, 2024
f215024
ignore functions
mengweieric Jul 13, 2024
2a452e9
case insensitive
mengweieric Jul 14, 2024
7ae59f4
change to use grammar for insensitive case
mengweieric Jul 14, 2024
64c266d
fix multi-line issue
mengweieric Jul 16, 2024
7c62bf7
code cleanup
mengweieric Jul 17, 2024
c9da113
move ppl out of scope
mengweieric Jul 17, 2024
140114a
rename folder and add ignoring rules
mengweieric Jul 18, 2024
f1014b7
resolve type issue
mengweieric Jul 18, 2024
152a645
fix ppl suggestion provider issue
mengweieric Jul 18, 2024
79e7782
remove function suggestion
mengweieric Jul 19, 2024
4d84d3b
some code clean up and adding tests
mengweieric Jul 20, 2024
609a2a9
sync main and resolve conflicts
mengweieric Jul 20, 2024
ce01e2c
cursor tests
mengweieric Jul 20, 2024
d7e3bd4
remove testing setup
mengweieric Jul 20, 2024
3aa0dff
add changelog
mengweieric Jul 20, 2024
d1e2540
update yarn file
mengweieric Jul 20, 2024
a5d12e5
add missing testing library
mengweieric Jul 21, 2024
a606aa8
MDS integration
mengweieric Jul 22, 2024
12715a2
Merge branch 'main' into feature/antlr-autocomplete
mengweieric Jul 22, 2024
4a8300b
minor interface change and disable word based suggestion
mengweieric Jul 22, 2024
9cb77b8
update ID_LITERAL and recompile grammar
mengweieric Jul 22, 2024
7851dc3
column suggest for agg function
mengweieric Jul 22, 2024
8ccd18e
Merge branch 'main' into feature/antlr-autocomplete
mengweieric Jul 22, 2024
e0b5082
revert version
mengweieric Jul 22, 2024
1102148
opensearch sql syntax highlighting
mengweieric Jul 22, 2024
799c903
Merge branch 'main' into feature/antlr-autocomplete
mengweieric Jul 22, 2024
878beb9
add utility tests
mengweieric Jul 22, 2024
fae7267
symbol table test
mengweieric Jul 22, 2024
f9b7717
error listener test
mengweieric Jul 22, 2024
9009922
parse test
mengweieric Jul 22, 2024
f28f558
add suggestion provider to single line query editor
mengweieric Jul 22, 2024
1f9080b
remove one test
mengweieric Jul 22, 2024
2fa1dfb
add connection service type
mengweieric Jul 22, 2024
3e5b430
Merge branch 'main' into feature/antlr-autocomplete
mengweieric Jul 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ target
/packages/osd-test/src/functional_test_runner/lib/config/__tests__/fixtures/
/packages/osd-ui-framework/dist
/packages/osd-ui-shared-deps/flot_charts

# antlr overrides
/src/plugins/data/public/antlr/opensearch_sql/.generated/*
/src/plugins/data/public/antlr/opensearch_sql/grammar/**/*
9 changes: 9 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,5 +751,14 @@ module.exports = {
'no-undef': 'off',
},
},
{
files: [
'src/plugins/data/public/antlr/opensearch_sql/.generated/*',
'src/plugins/data/public/antlr/opensearch_sql/grammar/**/*',
],
rules: {
'filenames/match-regex': 'off',
},
},
],
};
2 changes: 2 additions & 0 deletions changelogs/fragments/7336.yml
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))
2 changes: 1 addition & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,4 @@
# Set the backend roles in groups or users, whoever has the backend roles or exactly match the user ids defined in this config will be regard as dashboard admin.
# Dashboard admin will have the access to all the workspaces(workspace.enabled: true) and objects inside OpenSearch Dashboards.
# opensearchDashboards.dashboardAdmin.groups: ["dashboard_admin"]
# opensearchDashboards.dashboardAdmin.users: ["dashboard_admin"]
# opensearchDashboards.dashboardAdmin.users: ["dashboard_admin"]
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Contributor

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

Copy link
Collaborator Author

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

},
"repository": {
"type": "git",
Expand Down Expand Up @@ -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/hoek@6.1.3",
"**/trim": "^0.0.3",
"**/typescript": "4.6.4",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions packages/osd-babel-preset/webpack_preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ module.exports = () => {
fileName: false,
},
],
[
require.resolve('@babel/plugin-transform-class-static-block'),
{
fileName: false,
},
],
],
env: {
production: {
Expand Down
3 changes: 3 additions & 0 deletions packages/osd-monaco/src/xjson/lexer_rules/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import * as monaco from 'monaco-editor/esm/vs/editor/editor.api';
import * as xJson from './xjson';
import * as opensearchql from './opensearchql';
import * as painless from './painless';
import * as opensearchsql from './opensearchsql';

export const registerLexerRules = (m: typeof monaco) => {
m.languages.register({ id: xJson.ID });
Expand All @@ -41,4 +42,6 @@ export const registerLexerRules = (m: typeof monaco) => {
m.languages.setMonarchTokensProvider(painless.ID, painless.lexerRules);
m.languages.register({ id: opensearchql.ID });
m.languages.setMonarchTokensProvider(opensearchql.ID, opensearchql.lexerRules);
m.languages.register({ id: opensearchsql.ID });
m.languages.setMonarchTokensProvider(opensearchsql.ID, opensearchsql.lexerRules);
};
157 changes: 157 additions & 0 deletions packages/osd-monaco/src/xjson/lexer_rules/opensearchsql.ts
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;
10 changes: 10 additions & 0 deletions packages/osd-optimizer/src/worker/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@ export function getWebpackConfig(bundle: Bundle, bundleRefs: BundleRefs, worker:
loader: 'raw-loader',
},
},
{
test: /\.cjs$/,
include: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [BABEL_PRESET_PATH],
},
},
},
],
},

Expand Down
Loading
Loading