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.
[SQL] initial commit for SQL language selector
Only adds the quick startup for OpenSearch cluster with a SQL plugin and observability with: ``` yarn opensearch snapshot --sql ``` Also, adds SQL to the language selector stolen shamelessly from opensearch-project#5623 Next steps to intercept and send to SQL API or just transform basic syntax to DSL Signed-off-by: Kawika Avilla <[email protected]>
- Loading branch information
Showing
12 changed files
with
150 additions
and
101 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
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
21 changes: 21 additions & 0 deletions
21
src/plugins/data/common/opensearch_query/opensearch_query/from_sql.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,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { decorateQuery } from './decorate_query'; | ||
import { getIndexPatternFromSql, sqlStringToDsl } from './sql_string_to_dsl'; | ||
import { Query } from '../../query/types'; | ||
|
||
export function buildQueryFromSql(queries: Query[], dateFormatTZ?: string) { | ||
const combinedQueries = (queries || []).map((query) => { | ||
const indexPattern = getIndexPatternFromSql(query.query); | ||
const queryDsl = sqlStringToDsl(query.query); | ||
|
||
return decorateQuery(queryDsl, indexPattern, dateFormatTZ); | ||
}); | ||
|
||
return { | ||
combinedQueries, | ||
}; | ||
} |
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
23 changes: 23 additions & 0 deletions
23
src/plugins/data/common/opensearch_query/opensearch_query/sql_string_to_dsl.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,23 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { isString } from 'lodash'; | ||
import { DslQuery } from './opensearch_query_dsl'; | ||
|
||
export function getIndexPatternFromSql(query: string | any) { | ||
const from = query.match(new RegExp(/FROM\s+([\w*-.!@$^()~;]+)/, 'i')); | ||
if (from) { | ||
return from[1]; | ||
} | ||
return ''; | ||
} | ||
|
||
export function sqlStringToDsl(query: string | any): DslQuery { | ||
if (isString(query)) { | ||
return { query_string: { query } }; | ||
} | ||
|
||
return query; | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
@import "./query_bar"; | ||
@import "./language_switcher" |
4 changes: 4 additions & 0 deletions
4
src/plugins/data/public/ui/query_string_input/_language_switcher.scss
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,4 @@ | ||
// From: https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5623 | ||
.languageSwitcher { | ||
max-width: 150px; | ||
} |
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