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] DQL autosuggest with ANTLR #7391

Merged
merged 47 commits into from
Jul 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
18ef962
Antlr autocomplete (#7159)
paulstn Jul 2, 2024
984bd9b
dql Antlr autocomplete (#7160)
paulstn Jul 2, 2024
0a5d481
remove EOF in parser to fix suggestions
paulstn Jul 11, 2024
5d33ea1
use custom version of cursor token index for dql
paulstn Jul 13, 2024
95969f0
implemented value suggestions based on field
paulstn Jul 15, 2024
51acd0a
set param type
paulstn Jul 15, 2024
fefd947
update grouping grammar
paulstn Jul 17, 2024
3d04587
fix grammar for dots in field and value term search with spaces
paulstn Jul 17, 2024
4282d74
value suggestions match field to avoid failing api call and to find a…
paulstn Jul 17, 2024
08807f1
update value suggestions from partially formed value
paulstn Jul 17, 2024
01ec3c7
refactor value suggestions and change fieldval listener to visitor
paulstn Jul 17, 2024
dc48692
implement value suggestions within phrases
paulstn Jul 17, 2024
9b2b513
make grammar more readable
paulstn Jul 18, 2024
09fc01a
rename grammar parser rules
paulstn Jul 18, 2024
d48cab9
bring back minimal autocomplete optimized grammar
paulstn Jul 18, 2024
e1d5049
enable partially complete value suggestion for value groups
paulstn Jul 18, 2024
2e2adca
remove number as lexer rule
paulstn Jul 19, 2024
cdfd8d0
fix cursor import and clean up
paulstn Jul 19, 2024
bacb5d8
fix completion item range to be current word
paulstn Jul 19, 2024
da79597
update cursor to use monaco position
paulstn Jul 20, 2024
792c37c
cursor index to use position directly
paulstn Jul 20, 2024
760272c
move language registration into render function to handle new languages
paulstn Jul 22, 2024
30054a8
include auto closing quotes and parenthesis for dql
paulstn Jul 22, 2024
c46e521
rename generated file
paulstn Jul 22, 2024
698bb38
Changeset file for PR #7391 created/updated
opensearch-changeset-bot[bot] Jul 23, 2024
68911aa
add license and fix linting
paulstn Jul 23, 2024
3b13cf1
modify grammar
paulstn Jul 23, 2024
04e3f61
add tests for fields and keywords
paulstn Jul 23, 2024
8f36279
move dql test constants to separate file
paulstn Jul 23, 2024
9787c6e
pass core setup from autocomplete constructor to query sugg provider …
paulstn Jul 23, 2024
99ee35a
update an import
paulstn Jul 24, 2024
d6519a3
use updated dataset for index pattern
paulstn Jul 25, 2024
443bf72
remove console log
paulstn Jul 25, 2024
bdc45c1
[Auto Suggest] DQL Updates (#7498)
paulstn Jul 25, 2024
7a8ef87
update saved object test flyout snap
paulstn Jul 26, 2024
00fe412
update tests to match changes
paulstn Jul 26, 2024
3be2116
updated editor
paulstn Jul 29, 2024
c799ae5
insert colon and space after selecting suggested field
paulstn Jul 29, 2024
e65080a
fix suggestions after colon without space
paulstn Jul 29, 2024
c14afd2
update test
paulstn Jul 29, 2024
dfe3ffd
typing update
paulstn Jul 29, 2024
da49684
updated dataset name
paulstn Jul 29, 2024
d5184f6
remove connection service based lines and rely on service
paulstn Jul 30, 2024
1cd99fd
add debouncer for index pattern calls
paulstn Jul 30, 2024
b1b4095
use index pattern service rather than debounce
paulstn Jul 30, 2024
b182ce8
update mock index for test
paulstn Jul 30, 2024
d3db8da
Merge branch 'main' into antlr-autocomplete
paulstn Jul 30, 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
Prev Previous commit
Next Next commit
update value suggestions from partially formed value
Signed-off-by: Paul Sebastian <paulstn@amazon.com>
  • Loading branch information
paulstn committed Jul 30, 2024
commit 08807f1c99fea339b54387932045bdf4b708d10b
23 changes: 16 additions & 7 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CharStream, CommonTokenStream, TokenStream } from 'antlr4ng';
import { DQLLexer } from './generated/DQLLexer';
import { DQLParser, FieldContext } from './generated/DQLParser';
import { DQLParser, FieldContext, ValueContext } from './generated/DQLParser';
import { CodeCompletionCore } from 'antlr4-c3';
import { getTokenPosition } from '../opensearch_sql/cursor';
import { IndexPattern, IndexPatternField } from '../../index_patterns';
Expand Down Expand Up @@ -52,17 +52,18 @@ const findFieldSuggestions = (indexPattern: IndexPattern) => {
return fieldSuggestions;
};

const findValuesFromField = async (indexTitle: string, fieldName: string) => {
const findValuesFromField = async (indexTitle: string, fieldName: string, currentValue: string) => {
const http = getHttp();
return await http.fetch(`/api/opensearch-dashboards/suggestions/values/${indexTitle}`, {
method: 'POST',
body: JSON.stringify({ query: '', field: fieldName, boolFilter: [] }),
body: JSON.stringify({ query: currentValue, field: fieldName, boolFilter: [] }),
});
};

// listener for parsing the current query
class FieldListener extends DQLParserListener {
lastField: string | undefined;
lastValue: string | undefined;

constructor() {
super();
Expand All @@ -73,8 +74,12 @@ class FieldListener extends DQLParserListener {
this.lastField = ctx.start?.text;
};

getLastField() {
return this.lastField;
public enterValue = (ctx: ValueContext) => {
this.lastValue = ctx.start?.text;
};

getLastFieldValue() {
return { field: this.lastField, value: this.lastValue };
}
}

Expand Down Expand Up @@ -128,7 +133,7 @@ export const getSuggestions = async ({
}

// find suggested values for the last found field
const lastField = listener.getLastField();
const { field: lastField, value: lastValue } = listener.getLastFieldValue();
if (!!lastField && candidates.tokens.has(DQLParser.PHRASE)) {
// check to see if last field is within index and if it can suggest values, first check
// if .keyword appended field exists because that has values
Expand All @@ -144,7 +149,11 @@ export const getSuggestions = async ({
if (!matchedField || !matchedField.aggregatable || matchedField.type !== 'string') return;

// ask api for suggestions
const values = await findValuesFromField(currentIndexPattern.title, matchedField.displayName);
const values = await findValuesFromField(
currentIndexPattern.title,
matchedField.displayName,
lastValue ?? ''
);
console.log(values);
completions.push(
...values.map((val: any) => {
Expand Down