diff --git a/.gitignore b/.gitignore index 99457f958f5b..c530adedb7bb 100644 --- a/.gitignore +++ b/.gitignore @@ -70,4 +70,5 @@ snapshots.js .yarn-local-mirror # Ignore the generated antlr files -/src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr \ No newline at end of file +/src/plugins/data/public/antlr/opensearch_sql/grammar/.antlr +/src/plugins/data/public/antlr/dql/grammar/.antlr \ No newline at end of file diff --git a/changelogs/fragments/7593.yml b/changelogs/fragments/7593.yml new file mode 100644 index 000000000000..d08a386a3978 --- /dev/null +++ b/changelogs/fragments/7593.yml @@ -0,0 +1,2 @@ +fix: +- Update DQL Autocomplete in code and functionality ([#7593](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/7593)) \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/code_completion.test.ts b/src/plugins/data/public/antlr/dql/code_completion.test.ts index d8f75ebf0e1c..583976126965 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.test.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.test.ts @@ -5,12 +5,241 @@ import { monaco } from '@osd/monaco'; import { getSuggestions } from './code_completion'; -import { - booleanOperatorSuggestions, - fieldNameWithNotSuggestions, - notOperatorSuggestion, - testingIndex, -} from '../shared/constants'; +import { DataPublicPluginStart, IDataPluginServices } from '../../types'; +import { IndexPattern } from '../../index_patterns'; + +/** + * Constants + */ + +const testingIndex = ({ + title: 'opensearch_dashboards_sample_data_flights', + fields: [ + { + count: 0, + name: 'Carrier', + displayName: 'Carrier', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 2, + name: 'DestCityName', + displayName: 'DestCityName', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'DestCountry', + displayName: 'DestCountry', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'DestWeather', + displayName: 'DestWeather', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'DistanceMiles', + displayName: 'DistanceMiles', + type: 'number', + esTypes: ['float'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'FlightDelay', + displayName: 'FlightDelay', + type: 'boolean', + esTypes: ['boolean'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'FlightNum', + displayName: 'FlightNum', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: 'OriginWeather', + displayName: 'OriginWeather', + type: 'string', + esTypes: ['keyword'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: true, + subType: undefined, + }, + { + count: 0, + name: '_id', + displayName: '_id', + type: 'string', + esTypes: ['_id'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: false, + subType: undefined, + }, + { + count: 0, + name: '_index', + displayName: '_index', + type: 'string', + esTypes: ['_index'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: false, + subType: undefined, + }, + { + count: 0, + name: '_score', + displayName: '_score', + type: 'number', + scripted: false, + searchable: false, + aggregatable: false, + readFromDocValues: false, + subType: undefined, + }, + { + count: 0, + name: '_source', + displayName: '_source', + type: '_source', + esTypes: ['_source'], + scripted: false, + searchable: false, + aggregatable: false, + readFromDocValues: false, + subType: undefined, + }, + { + count: 0, + name: '_type', + displayName: '_type', + type: 'string', + esTypes: ['_type'], + scripted: false, + searchable: true, + aggregatable: true, + readFromDocValues: false, + subType: undefined, + }, + ], +} as unknown) as IndexPattern; + +const booleanOperatorSuggestions = [ + { end: -1, start: -1, text: 'or', type: 17 }, + { end: -1, start: -1, text: 'and', type: 17 }, +]; + +const notOperatorSuggestion = { text: 'not', type: 17, end: -1, start: -1 }; + +const fieldNameSuggestions: Array<{ + text: string; + type: number; + insertText?: string; + end: number; + start: number; +}> = [ + { text: 'Carrier', type: 3, insertText: 'Carrier: ', end: -1, start: -1 }, + { text: 'DestCityName', type: 3, insertText: 'DestCityName: ', end: -1, start: -1 }, + { text: 'DestCountry', type: 3, insertText: 'DestCountry: ', end: -1, start: -1 }, + { text: 'DestWeather', type: 3, insertText: 'DestWeather: ', end: -1, start: -1 }, + { text: 'DistanceMiles', type: 3, insertText: 'DistanceMiles: ', end: -1, start: -1 }, + { text: 'FlightDelay', type: 3, insertText: 'FlightDelay: ', end: -1, start: -1 }, + { text: 'FlightNum', type: 3, insertText: 'FlightNum: ', end: -1, start: -1 }, + { text: 'OriginWeather', type: 3, insertText: 'OriginWeather: ', end: -1, start: -1 }, + { text: '_id', type: 3, insertText: '_id: ', end: -1, start: -1 }, + { text: '_index', type: 3, insertText: '_index: ', end: -1, start: -1 }, + { text: '_score', type: 3, insertText: '_score: ', end: -1, start: -1 }, + { text: '_source', type: 3, insertText: '_source: ', end: -1, start: -1 }, + { text: '_type', type: 3, insertText: '_type: ', end: -1, start: -1 }, +]; + +const fieldNameWithNotSuggestions = fieldNameSuggestions.concat(notOperatorSuggestion); + +const carrierValues = [ + 'Logstash Airways', + 'BeatsWest', + 'OpenSearch Dashboards Airlines', + 'OpenSearch-Air', +]; + +const allCarrierValueSuggestions = [ + { text: 'Logstash Airways', type: 13, start: -1, end: -1 }, + { text: 'BeatsWest', type: 13, start: -1, end: -1 }, + { + text: 'OpenSearch Dashboards Airlines', + type: 13, + start: -1, + end: -1, + }, + { text: 'OpenSearch-Air', type: 13, start: -1, end: -1 }, +]; + +const carrierWithNotSuggestions = allCarrierValueSuggestions.concat(notOperatorSuggestion); + +const logCarrierValueSuggestion = [{ text: 'Logstash Airways', type: 13, start: -1, end: -1 }]; + +const openCarrierValueSuggestion = [ + { + text: 'OpenSearch Dashboards Airlines', + type: 13, + start: -1, + end: -1, + }, + { text: 'OpenSearch-Air', type: 13, start: -1, end: -1 }, +]; + +/** + * Actual Tests + */ jest.mock('../../services', () => ({ getUiService: () => ({ @@ -20,6 +249,14 @@ jest.mock('../../services', () => ({ }), })); +const mockValueSuggestions = jest.fn((passedin) => { + const { field, query } = passedin; + if (field?.name === 'Carrier') { + return carrierValues.filter((val) => val.startsWith(query)); + } + return []; +}); + const getSuggestionsAtPos = async (query: string, endPos: number) => { return await getSuggestions({ query, @@ -28,47 +265,84 @@ const getSuggestionsAtPos = async (query: string, endPos: number) => { language: '', // not relevant selectionEnd: 0, // not relevant selectionStart: 0, // not relevant - services: { appName: 'discover' }, + services: { + appName: 'discover', + data: ({ + autocomplete: { getValueSuggestions: mockValueSuggestions }, + } as unknown) as DataPublicPluginStart, + } as IDataPluginServices, }); }; -const getSuggestionAtEnd = async (query: string) => { +const getSuggestionsAtEnd = async (query: string) => { return await getSuggestionsAtPos(query, query.length + 1); }; +const testAroundClosing = ( + query: string, + surroundingChars: Array, + testName: string, + expectedValue: any, + includeBase?: boolean +) => { + if (includeBase) { + it(testName, async () => { + expect(await getSuggestionsAtEnd(query)).toStrictEqual(expectedValue); + }); + } + + let currQuery = query; + if (surroundingChars[0]) { + it(testName + ' - opened', async () => { + currQuery = currQuery + surroundingChars[0]; + expect(await getSuggestionsAtEnd(currQuery)).toStrictEqual(expectedValue); + }); + } + + it(testName + ' - closed', async () => { + currQuery = currQuery + surroundingChars[1]; + expect(await getSuggestionsAtPos(currQuery, currQuery.length)).toStrictEqual(expectedValue); + }); + + // TODO: besides NOT issue, need to consolidate behavior where there is no val vs w/ val + it.skip(testName + ' - no suggestion after closing', async () => { + expect(await getSuggestionsAtEnd(currQuery)).toStrictEqual([]); + }); +}; + describe('Test Boolean Operators', () => { it('should suggest AND and OR after expression', async () => { - expect(await getSuggestionAtEnd('field: value ')).toStrictEqual(booleanOperatorSuggestions); + expect(await getSuggestionsAtEnd('field: value ')).toStrictEqual(booleanOperatorSuggestions); }); it('should suggest NOT initially', async () => { - expect(await getSuggestionAtEnd('')).toContainEqual(notOperatorSuggestion); + expect(await getSuggestionsAtEnd('')).toContainEqual(notOperatorSuggestion); }); it('should suggest NOT after expression', async () => { - expect(await getSuggestionAtEnd('field: value and ')).toContainEqual(notOperatorSuggestion); + expect(await getSuggestionsAtEnd('field: value and ')).toContainEqual(notOperatorSuggestion); }); it('should not suggest NOT twice', async () => { - expect(await getSuggestionAtEnd('not ')).not.toContainEqual(notOperatorSuggestion); + expect(await getSuggestionsAtEnd('not ')).not.toContainEqual(notOperatorSuggestion); }); it('should suggest after multiple token search', async () => { - expect(await getSuggestionAtEnd('field: one two three ')).toStrictEqual( + expect(await getSuggestionsAtEnd('field: one two three ')).toStrictEqual( booleanOperatorSuggestions ); }); it('should suggest after phrase value', async () => { - expect(await getSuggestionAtEnd('field: "value" ')).toStrictEqual(booleanOperatorSuggestions); + expect(await getSuggestionsAtEnd('field: "value" ')).toStrictEqual(booleanOperatorSuggestions); }); it('should suggest after number', async () => { - expect(await getSuggestionAtEnd('field: 123 ')).toStrictEqual(booleanOperatorSuggestions); + expect(await getSuggestionsAtEnd('field: 123 ')).toStrictEqual(booleanOperatorSuggestions); }); it('should not suggest after incomplete quote', async () => { - expect(await getSuggestionAtEnd('field: "value ')).not.toStrictEqual( + expect(await getSuggestionsAtEnd('field: "value ')).not.toStrictEqual( booleanOperatorSuggestions ); }); @@ -76,15 +350,15 @@ describe('Test Boolean Operators', () => { describe('Test Boolean Operators within groups', () => { it('should suggest AND and OR', async () => { - expect(await getSuggestionAtEnd('field: (value ')).toStrictEqual(booleanOperatorSuggestions); + expect(await getSuggestionsAtEnd('field: (value ')).toStrictEqual(booleanOperatorSuggestions); }); it('should suggest NOT after expression', async () => { - expect(await getSuggestionAtEnd('field: (value and ')).toContainEqual(notOperatorSuggestion); + expect(await getSuggestionsAtEnd('field: (value and ')).toContainEqual(notOperatorSuggestion); }); it('should suggest operator within nested group', async () => { - expect(await getSuggestionAtEnd('field: ("one" and ("two" ')).toStrictEqual( + expect(await getSuggestionsAtEnd('field: ("one" and ("two" ')).toStrictEqual( booleanOperatorSuggestions ); }); @@ -92,18 +366,133 @@ describe('Test Boolean Operators within groups', () => { describe('Test field suggestions', () => { it('basic field suggestion', async () => { - expect(await getSuggestionAtEnd('')).toStrictEqual(fieldNameWithNotSuggestions); + expect(await getSuggestionsAtEnd('')).toStrictEqual(fieldNameWithNotSuggestions); }); it('field suggestion after one term', async () => { - expect(await getSuggestionAtEnd('field: value and ')).toStrictEqual( + expect(await getSuggestionsAtEnd('field: value and ')).toStrictEqual( fieldNameWithNotSuggestions ); }); it('field suggestion within group', async () => { - expect(await getSuggestionAtEnd('field: value and (one: "two" or ')).toStrictEqual( + expect(await getSuggestionsAtEnd('field: value and (one: "two" or ')).toStrictEqual( fieldNameWithNotSuggestions ); }); }); + +describe('Test basic value suggestions', () => { + it('do not suggest unknown field', async () => { + expect(await getSuggestionsAtEnd('field: ')).toStrictEqual([]); + }); + + it('suggest token search value for field', async () => { + expect(await getSuggestionsAtEnd('Carrier: ')).toStrictEqual(allCarrierValueSuggestions); + }); + + it('suggest value for field without surrounding space', async () => { + expect(await getSuggestionsAtEnd('Carrier:')).toStrictEqual(allCarrierValueSuggestions); + }); + + it('suggest value from partial value', async () => { + expect(await getSuggestionsAtEnd('Carrier: Log')).toStrictEqual(logCarrierValueSuggestion); + }); + + it('suggest multiple values from partial value', async () => { + expect(await getSuggestionsAtEnd('Carrier: Open')).toStrictEqual(openCarrierValueSuggestion); + }); + + testAroundClosing( + 'Carrier: ', + ['"', '"'], + 'should suggest within phrase', + allCarrierValueSuggestions + ); + + it('suggest rest of partial value within quotes', async () => { + const query = 'Carrier: "OpenSearch"'; + expect(await getSuggestionsAtPos(query, query.length)).toStrictEqual( + openCarrierValueSuggestion + ); + }); + + // it('should suggest within multiple token search context'); <-- maybe it means suggest either bool OR next partial value +}); + +describe('Test value suggestion with multiple terms', () => { + testAroundClosing( + 'Carrier: BeatsWest or Carrier: ', + ['"', '"'], + 'should suggest after one field value expression', + allCarrierValueSuggestions, + true + ); + + it('should suggest after field value expression and partial value', async () => { + expect(await getSuggestionsAtEnd('Carrier: BeatsWest or Carrier: Open')).toStrictEqual( + openCarrierValueSuggestion + ); + }); + + testAroundClosing( + 'Carrier: BeatsWest or Carrier: "Open', + [undefined, '"'], + 'should suggest after field value expression in partial value quotes', + openCarrierValueSuggestion, + true + ); +}); + +describe('Test group value suggestions', () => { + testAroundClosing( + 'Carrier: ', + ['(', ')'], + 'should suggest within grouping', + carrierWithNotSuggestions + ); + + testAroundClosing( + 'Carrier: (', + ['"', '"'], + 'should suggest within grouping and phrase', + allCarrierValueSuggestions + ); + + testAroundClosing( + 'Carrier: ("', + [undefined, '")'], + 'should suggest within closed grouping and phrase', + allCarrierValueSuggestions + ); + + testAroundClosing( + 'Carrier: (BeatsWest or ', + [undefined, ')'], + 'should suggest after grouping with term', + carrierWithNotSuggestions, + true + ); + + testAroundClosing( + 'Carrier: (BeatsWest or ', + ['"', '")'], + 'should suggest in phrase after grouping with term', + allCarrierValueSuggestions + ); + + testAroundClosing( + 'Carrier: ("BeatsWest" or ', + [undefined, ')'], + 'should suggest after grouping with phrase', + carrierWithNotSuggestions, + true + ); + + testAroundClosing( + 'Carrier: ("BeatsWest" or ', + ['"', '")'], + 'should suggest in phrase after grouping with phrase', + allCarrierValueSuggestions + ); +}); diff --git a/src/plugins/data/public/antlr/dql/code_completion.ts b/src/plugins/data/public/antlr/dql/code_completion.ts index 6a10a519abaf..025c2118fbc7 100644 --- a/src/plugins/data/public/antlr/dql/code_completion.ts +++ b/src/plugins/data/public/antlr/dql/code_completion.ts @@ -5,30 +5,33 @@ import { CharStream, CommonTokenStream, TokenStream } from 'antlr4ng'; import { CodeCompletionCore } from 'antlr4-c3'; -import { HttpSetup } from 'opensearch-dashboards/public'; import { monaco } from '@osd/monaco'; import { DQLLexer } from './.generated/DQLLexer'; -import { DQLParser, KeyValueExpressionContext } from './.generated/DQLParser'; +import { + DQLParser, + GroupContentContext, + GroupExpressionContext, + KeyValueExpressionContext, +} from './.generated/DQLParser'; import { getTokenPosition } from '../shared/cursor'; import { IndexPattern, IndexPatternField } from '../../index_patterns'; -import { QuerySuggestionGetFnArgs } from '../../autocomplete'; +import { QuerySuggestion, QuerySuggestionGetFnArgs } from '../../autocomplete'; import { DQLParserVisitor } from './.generated/DQLParserVisitor'; +import { IDataPluginServices } from '../..'; import { getQueryService } from '../../services'; const findCursorIndex = ( tokenStream: TokenStream, cursorColumn: number, - cursorLine: number, - whitespaceToken: number + cursorLine: number ): number | undefined => { - const actualCursorCol = cursorColumn - 1; - for (let i = 0; i < tokenStream.size; i++) { const token = tokenStream.get(i); - const { startLine, endColumn, endLine } = getTokenPosition(token, whitespaceToken); + const { startLine, endColumn, endLine } = getTokenPosition(token, DQLParser.WS); - if (endLine > cursorLine || (startLine === cursorLine && endColumn >= actualCursorCol)) { - if (tokenStream.get(i).type === whitespaceToken || tokenStream.get(i).type === DQLParser.EQ) { + const moveToNextToken = [DQLParser.WS, DQLParser.EQ, DQLParser.LPAREN]; + if (endLine > cursorLine || (startLine === cursorLine && endColumn >= cursorColumn)) { + if (moveToNextToken.includes(tokenStream.get(i).type)) { return i + 1; } return i; @@ -45,38 +48,26 @@ const findFieldSuggestions = (indexPattern: IndexPattern) => { return idxField.name; }); - const fieldSuggestions: Array<{ - text: string; - type: monaco.languages.CompletionItemKind; - }> = fieldNames.map((field: string) => { + const fieldSuggestions: QuerySuggestion[] = fieldNames.map((field: string) => { return { text: field, type: monaco.languages.CompletionItemKind.Field, insertText: `${field}: `, + start: -1, + end: -1, }; }); return fieldSuggestions; }; -const getFieldSuggestedValues = async ( - indexTitle: string, - fieldName: string, - currentValue: string, - http?: HttpSetup -) => { - if (!http) return []; - return await http.fetch(`/api/opensearch-dashboards/suggestions/values/${indexTitle}`, { - method: 'POST', - body: JSON.stringify({ query: currentValue, field: fieldName, boolFilter: [] }), - }); -}; - const findValueSuggestions = async ( index: IndexPattern, field: string, value: string, - http?: HttpSetup + services: IDataPluginServices, + boolFilter?: any, + signal?: AbortSignal ) => { // 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 @@ -90,45 +81,26 @@ const findValueSuggestions = async ( if (idxField.name === field) return idxField; }); - if (matchedField?.type === 'boolean') { - return ['true', 'false']; - } - - if (!matchedField || !matchedField.aggregatable || matchedField.type !== 'string') return; + if (!matchedField) return; - // ask api for suggestions - return await getFieldSuggestedValues(index.title, matchedField.name, value, http); + return await services?.data.autocomplete.getValueSuggestions({ + indexPattern: index, + field: matchedField, + query: value, + boolFilter, + signal, + }); }; -// visitor for parsing the current query -class QueryVisitor extends DQLParserVisitor<{ field: string; value: string }> { - public visitKeyValueExpression = (ctx: KeyValueExpressionContext) => { - let foundValue = ''; - const getTextWithoutQuotes = (text: string | undefined) => text?.replace(/^["']|["']$/g, ''); - - if (ctx.value()?.PHRASE()) { - const phraseText = getTextWithoutQuotes(ctx.value()?.PHRASE()?.getText()); - if (phraseText) foundValue = phraseText; - } else if (ctx.value()?.tokenSearch()) { - const valueText = ctx.value()?.getText(); - if (valueText) foundValue = valueText; - } else if (ctx.groupExpression()) { - const lastGroupContent = getTextWithoutQuotes( - ctx.groupExpression()?.groupContent().at(-1)?.getText() - ); - if (lastGroupContent) foundValue = lastGroupContent; - } - return { field: ctx.field().getText(), value: foundValue }; - }; -} - export const getSuggestions = async ({ query, indexPattern, position, selectionEnd, services, -}: QuerySuggestionGetFnArgs) => { + boolFilter, + signal, +}: QuerySuggestionGetFnArgs): Promise => { if ( !services || !services.appName || @@ -141,8 +113,6 @@ export const getSuggestions = async ({ return []; } try { - const http = services.http; - const inputStream = CharStream.fromString(query); const lexer = new DQLLexer(inputStream); const tokenStream = new CommonTokenStream(lexer); @@ -150,13 +120,11 @@ export const getSuggestions = async ({ parser.removeErrorListeners(); const tree = parser.query(); - const visitor = new QueryVisitor(); - // find token index - const cursorColumn = position?.column ?? selectionEnd; + const cursorColumn = position?.column !== undefined ? position.column - 1 : selectionEnd; const cursorLine = position?.lineNumber ?? 1; - const cursorIndex = findCursorIndex(tokenStream, cursorColumn, cursorLine, DQLParser.WS) ?? 0; + const cursorIndex = findCursorIndex(tokenStream, cursorColumn, cursorLine) ?? 0; const core = new CodeCompletionCore(parser); @@ -177,21 +145,123 @@ export const getSuggestions = async ({ // gets candidates at specified token index const candidates = core.collectCandidates(cursorIndex); - const completions = []; + // manually remove NOT from candidates when cursor is in a phrase + if (tokenStream.get(cursorIndex).type === DQLParser.PHRASE) { + candidates.tokens.delete(DQLParser.NOT); + } + + const completions: QuerySuggestion[] = []; // check to see if field rule is a candidate. if so, suggest field names if (candidates.rules.has(DQLParser.RULE_field)) { completions.push(...findFieldSuggestions(indexPattern)); } + interface FoundLastValue { + field: string | undefined; + value: string | undefined; + } + + // visitor for parsing the current query + class QueryVisitor extends DQLParserVisitor { + public defaultResult = () => { + return { field: undefined, value: undefined }; + }; + + public aggregateResult = (aggregate: FoundLastValue, nextResult: FoundLastValue) => { + if (nextResult.field) { + return nextResult; + } + return aggregate; + }; + + public visitKeyValueExpression = (ctx: KeyValueExpressionContext) => { + const startPos = ctx.start?.start ?? -1; + let endPos = ctx.stop?.stop ?? -1; + + // find the WS token after the last KV token, pushing endPos out if applicable + const { stop: lastKVToken } = ctx.getSourceInterval(); + if (tokenStream.get(lastKVToken + 1).type === DQLParser.WS) { + endPos = tokenStream.get(lastKVToken + 1).stop; + } + + // early return if the cursor is not within the bounds of this KV pair + if (!(startPos <= cursorColumn && endPos + 1 >= cursorColumn)) + return { field: undefined, value: undefined }; + + // keep as empty string to intentionally return so if no value is found in value() + let foundValue = ''; + const getTextWithoutQuotes = (text: string | undefined) => + text?.replace(/^["']|["']$/g, ''); + + if (ctx.value()?.PHRASE()) { + const phraseText = getTextWithoutQuotes(ctx.value()?.PHRASE()?.getText()); + if (phraseText) foundValue = phraseText; + } else if (ctx.value()?.tokenSearch()) { + const valueText = ctx.value()?.getText(); + if (valueText) foundValue = valueText; + } else if (ctx.groupExpression()) { + // continue calls down the tree for value group expressions + const groupRes = this.visitGroupExpression(ctx.groupExpression()!); + // only pull value off of groupRes, field should be undefined + const lastGroupContent = getTextWithoutQuotes(groupRes.value); + if (lastGroupContent) foundValue = lastGroupContent; + } + return { field: ctx.field().getText(), value: foundValue }; + }; + + public visitGroupExpression = (ctx: GroupExpressionContext) => { + let foundValue = ''; + + // within the multiple group contents, call visitor on each one + ctx.groupContent().forEach((child) => { + const ret = this.visitGroupContent(child); + if (ret.value) foundValue = ret.value; + }); + + return { field: undefined, value: foundValue }; + }; + + public visitGroupContent = (ctx: GroupContentContext) => { + const startPos = ctx.start?.start ?? -1; + const endPos = ctx.stop?.stop ?? -1; + + // NOTE: currently there is no support to look for tokens after whitespace, only + // returning if the cursor is directly touching a token + + if (!(startPos <= cursorColumn && endPos + 1 >= cursorColumn)) + return { field: undefined, value: undefined }; + + // trigger group expression to find content within + const foundValue = !!ctx.groupExpression() + ? this.visitGroupExpression(ctx.groupExpression()!).value + : ctx.getText(); + + return { field: undefined, value: foundValue }; + }; + } + + const visitor = new QueryVisitor(); // find suggested values for the last found field (only for kvexpression rule) const { field: lastField = '', value: lastValue = '' } = visitor.visit(tree) ?? {}; if (!!lastField && candidates.tokens.has(DQLParser.PHRASE)) { - const values = await findValueSuggestions(indexPattern, lastField, lastValue ?? '', http); + const values = await findValueSuggestions( + indexPattern, + lastField, + lastValue ?? '', + services, + boolFilter, + signal + ); if (!!values) { completions.push( ...values?.map((val: any) => { - return { text: val, type: monaco.languages.CompletionItemKind.Value }; + return { + text: val, + type: monaco.languages.CompletionItemKind.Value, + start: -1, + end: -1, + }; }) ); } @@ -205,10 +275,14 @@ export const getSuggestions = async ({ } const tokenSymbolName = parser.vocabulary.getSymbolicName(token)?.toLowerCase(); - completions.push({ - text: tokenSymbolName, - type: monaco.languages.CompletionItemKind.Keyword, - }); + if (tokenSymbolName) { + completions.push({ + text: tokenSymbolName, + type: monaco.languages.CompletionItemKind.Keyword, + start: -1, + end: -1, + }); + } }); return completions; diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.interp b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.interp deleted file mode 100644 index 2a27c7a74895..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.interp +++ /dev/null @@ -1,56 +0,0 @@ -token literal names: -null -null -null -null -'>' -'<' -'>=' -'<=' -':' -'(' -')' -null -null -null - -token symbolic names: -null -OR -AND -NOT -GT -LT -GE -LE -EQ -LPAREN -RPAREN -PHRASE -ID -WS - -rule names: -OR -AND -NOT -GT -LT -GE -LE -EQ -LPAREN -RPAREN -PHRASE -ID -WS - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 13, 78, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 8, 1, 8, 1, 9, 1, 9, 1, 10, 1, 10, 5, 10, 57, 8, 10, 10, 10, 12, 10, 60, 9, 10, 1, 10, 3, 10, 63, 8, 10, 1, 11, 1, 11, 5, 11, 67, 8, 11, 10, 11, 12, 11, 70, 9, 11, 1, 12, 4, 12, 73, 8, 12, 11, 12, 12, 12, 74, 1, 12, 1, 12, 0, 0, 13, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 1, 0, 10, 2, 0, 79, 79, 111, 111, 2, 0, 82, 82, 114, 114, 2, 0, 65, 65, 97, 97, 2, 0, 78, 78, 110, 110, 2, 0, 68, 68, 100, 100, 2, 0, 84, 84, 116, 116, 2, 0, 34, 34, 92, 92, 5, 0, 42, 42, 48, 57, 65, 90, 95, 95, 97, 122, 6, 0, 42, 42, 46, 46, 48, 57, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 81, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 1, 27, 1, 0, 0, 0, 3, 30, 1, 0, 0, 0, 5, 34, 1, 0, 0, 0, 7, 38, 1, 0, 0, 0, 9, 40, 1, 0, 0, 0, 11, 42, 1, 0, 0, 0, 13, 45, 1, 0, 0, 0, 15, 48, 1, 0, 0, 0, 17, 50, 1, 0, 0, 0, 19, 52, 1, 0, 0, 0, 21, 54, 1, 0, 0, 0, 23, 64, 1, 0, 0, 0, 25, 72, 1, 0, 0, 0, 27, 28, 7, 0, 0, 0, 28, 29, 7, 1, 0, 0, 29, 2, 1, 0, 0, 0, 30, 31, 7, 2, 0, 0, 31, 32, 7, 3, 0, 0, 32, 33, 7, 4, 0, 0, 33, 4, 1, 0, 0, 0, 34, 35, 7, 3, 0, 0, 35, 36, 7, 0, 0, 0, 36, 37, 7, 5, 0, 0, 37, 6, 1, 0, 0, 0, 38, 39, 5, 62, 0, 0, 39, 8, 1, 0, 0, 0, 40, 41, 5, 60, 0, 0, 41, 10, 1, 0, 0, 0, 42, 43, 5, 62, 0, 0, 43, 44, 5, 61, 0, 0, 44, 12, 1, 0, 0, 0, 45, 46, 5, 60, 0, 0, 46, 47, 5, 61, 0, 0, 47, 14, 1, 0, 0, 0, 48, 49, 5, 58, 0, 0, 49, 16, 1, 0, 0, 0, 50, 51, 5, 40, 0, 0, 51, 18, 1, 0, 0, 0, 52, 53, 5, 41, 0, 0, 53, 20, 1, 0, 0, 0, 54, 58, 5, 34, 0, 0, 55, 57, 8, 6, 0, 0, 56, 55, 1, 0, 0, 0, 57, 60, 1, 0, 0, 0, 58, 56, 1, 0, 0, 0, 58, 59, 1, 0, 0, 0, 59, 62, 1, 0, 0, 0, 60, 58, 1, 0, 0, 0, 61, 63, 5, 34, 0, 0, 62, 61, 1, 0, 0, 0, 62, 63, 1, 0, 0, 0, 63, 22, 1, 0, 0, 0, 64, 68, 7, 7, 0, 0, 65, 67, 7, 8, 0, 0, 66, 65, 1, 0, 0, 0, 67, 70, 1, 0, 0, 0, 68, 66, 1, 0, 0, 0, 68, 69, 1, 0, 0, 0, 69, 24, 1, 0, 0, 0, 70, 68, 1, 0, 0, 0, 71, 73, 7, 9, 0, 0, 72, 71, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 72, 1, 0, 0, 0, 74, 75, 1, 0, 0, 0, 75, 76, 1, 0, 0, 0, 76, 77, 6, 12, 0, 0, 77, 26, 1, 0, 0, 0, 5, 0, 58, 62, 68, 74, 1, 0, 1, 0] \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.java b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.java deleted file mode 100644 index 82d84ce79e61..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.java +++ /dev/null @@ -1,166 +0,0 @@ -// Generated from /Users/paulstn/Documents/opensearch-2.15.0/OpenSearch-Dashboards/src/plugins/data/public/antlr/dql/grammar/DQLLexer.g4 by ANTLR 4.13.1 -import org.antlr.v4.runtime.Lexer; -import org.antlr.v4.runtime.CharStream; -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.TokenStream; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.misc.*; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "this-escape"}) -public class DQLLexer extends Lexer { - static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - OR=1, AND=2, NOT=3, GT=4, LT=5, GE=6, LE=7, EQ=8, LPAREN=9, RPAREN=10, - PHRASE=11, ID=12, WS=13; - public static String[] channelNames = { - "DEFAULT_TOKEN_CHANNEL", "HIDDEN" - }; - - public static String[] modeNames = { - "DEFAULT_MODE" - }; - - private static String[] makeRuleNames() { - return new String[] { - "OR", "AND", "NOT", "GT", "LT", "GE", "LE", "EQ", "LPAREN", "RPAREN", - "PHRASE", "ID", "WS" - }; - } - public static final String[] ruleNames = makeRuleNames(); - - private static String[] makeLiteralNames() { - return new String[] { - null, null, null, null, "'>'", "'<'", "'>='", "'<='", "':'", "'('", "')'" - }; - } - private static final String[] _LITERAL_NAMES = makeLiteralNames(); - private static String[] makeSymbolicNames() { - return new String[] { - null, "OR", "AND", "NOT", "GT", "LT", "GE", "LE", "EQ", "LPAREN", "RPAREN", - "PHRASE", "ID", "WS" - }; - } - private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - - public DQLLexer(CharStream input) { - super(input); - _interp = new LexerATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @Override - public String getGrammarFileName() { return "DQLLexer.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public String[] getChannelNames() { return channelNames; } - - @Override - public String[] getModeNames() { return modeNames; } - - @Override - public ATN getATN() { return _ATN; } - - public static final String _serializedATN = - "\u0004\u0000\rN\u0006\uffff\uffff\u0002\u0000\u0007\u0000\u0002\u0001"+ - "\u0007\u0001\u0002\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004"+ - "\u0007\u0004\u0002\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007"+ - "\u0007\u0007\u0002\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b"+ - "\u0007\u000b\u0002\f\u0007\f\u0001\u0000\u0001\u0000\u0001\u0000\u0001"+ - "\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0001\u0002\u0001\u0002\u0001"+ - "\u0002\u0001\u0002\u0001\u0003\u0001\u0003\u0001\u0004\u0001\u0004\u0001"+ - "\u0005\u0001\u0005\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001"+ - "\u0007\u0001\u0007\u0001\b\u0001\b\u0001\t\u0001\t\u0001\n\u0001\n\u0005"+ - "\n9\b\n\n\n\f\n<\t\n\u0001\n\u0003\n?\b\n\u0001\u000b\u0001\u000b\u0005"+ - "\u000bC\b\u000b\n\u000b\f\u000bF\t\u000b\u0001\f\u0004\fI\b\f\u000b\f"+ - "\f\fJ\u0001\f\u0001\f\u0000\u0000\r\u0001\u0001\u0003\u0002\u0005\u0003"+ - "\u0007\u0004\t\u0005\u000b\u0006\r\u0007\u000f\b\u0011\t\u0013\n\u0015"+ - "\u000b\u0017\f\u0019\r\u0001\u0000\n\u0002\u0000OOoo\u0002\u0000RRrr\u0002"+ - "\u0000AAaa\u0002\u0000NNnn\u0002\u0000DDdd\u0002\u0000TTtt\u0002\u0000"+ - "\"\"\\\\\u0005\u0000**09AZ__az\u0006\u0000**..09AZ__az\u0003\u0000\t\n"+ - "\r\r Q\u0000\u0001\u0001\u0000\u0000\u0000\u0000\u0003\u0001\u0000\u0000"+ - "\u0000\u0000\u0005\u0001\u0000\u0000\u0000\u0000\u0007\u0001\u0000\u0000"+ - "\u0000\u0000\t\u0001\u0000\u0000\u0000\u0000\u000b\u0001\u0000\u0000\u0000"+ - "\u0000\r\u0001\u0000\u0000\u0000\u0000\u000f\u0001\u0000\u0000\u0000\u0000"+ - "\u0011\u0001\u0000\u0000\u0000\u0000\u0013\u0001\u0000\u0000\u0000\u0000"+ - "\u0015\u0001\u0000\u0000\u0000\u0000\u0017\u0001\u0000\u0000\u0000\u0000"+ - "\u0019\u0001\u0000\u0000\u0000\u0001\u001b\u0001\u0000\u0000\u0000\u0003"+ - "\u001e\u0001\u0000\u0000\u0000\u0005\"\u0001\u0000\u0000\u0000\u0007&"+ - "\u0001\u0000\u0000\u0000\t(\u0001\u0000\u0000\u0000\u000b*\u0001\u0000"+ - "\u0000\u0000\r-\u0001\u0000\u0000\u0000\u000f0\u0001\u0000\u0000\u0000"+ - "\u00112\u0001\u0000\u0000\u0000\u00134\u0001\u0000\u0000\u0000\u00156"+ - "\u0001\u0000\u0000\u0000\u0017@\u0001\u0000\u0000\u0000\u0019H\u0001\u0000"+ - "\u0000\u0000\u001b\u001c\u0007\u0000\u0000\u0000\u001c\u001d\u0007\u0001"+ - "\u0000\u0000\u001d\u0002\u0001\u0000\u0000\u0000\u001e\u001f\u0007\u0002"+ - "\u0000\u0000\u001f \u0007\u0003\u0000\u0000 !\u0007\u0004\u0000\u0000"+ - "!\u0004\u0001\u0000\u0000\u0000\"#\u0007\u0003\u0000\u0000#$\u0007\u0000"+ - "\u0000\u0000$%\u0007\u0005\u0000\u0000%\u0006\u0001\u0000\u0000\u0000"+ - "&\'\u0005>\u0000\u0000\'\b\u0001\u0000\u0000\u0000()\u0005<\u0000\u0000"+ - ")\n\u0001\u0000\u0000\u0000*+\u0005>\u0000\u0000+,\u0005=\u0000\u0000"+ - ",\f\u0001\u0000\u0000\u0000-.\u0005<\u0000\u0000./\u0005=\u0000\u0000"+ - "/\u000e\u0001\u0000\u0000\u000001\u0005:\u0000\u00001\u0010\u0001\u0000"+ - "\u0000\u000023\u0005(\u0000\u00003\u0012\u0001\u0000\u0000\u000045\u0005"+ - ")\u0000\u00005\u0014\u0001\u0000\u0000\u00006:\u0005\"\u0000\u000079\b"+ - "\u0006\u0000\u000087\u0001\u0000\u0000\u00009<\u0001\u0000\u0000\u0000"+ - ":8\u0001\u0000\u0000\u0000:;\u0001\u0000\u0000\u0000;>\u0001\u0000\u0000"+ - "\u0000<:\u0001\u0000\u0000\u0000=?\u0005\"\u0000\u0000>=\u0001\u0000\u0000"+ - "\u0000>?\u0001\u0000\u0000\u0000?\u0016\u0001\u0000\u0000\u0000@D\u0007"+ - "\u0007\u0000\u0000AC\u0007\b\u0000\u0000BA\u0001\u0000\u0000\u0000CF\u0001"+ - "\u0000\u0000\u0000DB\u0001\u0000\u0000\u0000DE\u0001\u0000\u0000\u0000"+ - "E\u0018\u0001\u0000\u0000\u0000FD\u0001\u0000\u0000\u0000GI\u0007\t\u0000"+ - "\u0000HG\u0001\u0000\u0000\u0000IJ\u0001\u0000\u0000\u0000JH\u0001\u0000"+ - "\u0000\u0000JK\u0001\u0000\u0000\u0000KL\u0001\u0000\u0000\u0000LM\u0006"+ - "\f\u0000\u0000M\u001a\u0001\u0000\u0000\u0000\u0005\u0000:>DJ\u0001\u0000"+ - "\u0001\u0000"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.tokens b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.tokens deleted file mode 100644 index d9da629fcca1..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLLexer.tokens +++ /dev/null @@ -1,20 +0,0 @@ -OR=1 -AND=2 -NOT=3 -GT=4 -LT=5 -GE=6 -LE=7 -EQ=8 -LPAREN=9 -RPAREN=10 -PHRASE=11 -ID=12 -WS=13 -'>'=4 -'<'=5 -'>='=6 -'<='=7 -':'=8 -'('=9 -')'=10 diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.interp b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.interp deleted file mode 100644 index 041e2baeae19..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.interp +++ /dev/null @@ -1,50 +0,0 @@ -token literal names: -null -null -null -null -'>' -'<' -'>=' -'<=' -':' -'(' -')' -null -null -null - -token symbolic names: -null -OR -AND -NOT -GT -LT -GE -LE -EQ -LPAREN -RPAREN -PHRASE -ID -WS - -rule names: -query -operatorExpression -booleanOperator -notExpression -primaryExpression -comparisonExpression -keyValueExpression -tokenSearch -groupExpression -groupContent -field -value -comparisonOperator - - -atn: -[4, 1, 13, 100, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 5, 1, 33, 8, 1, 10, 1, 12, 1, 36, 9, 1, 1, 2, 1, 2, 1, 3, 3, 3, 41, 8, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 1, 4, 3, 4, 52, 8, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 3, 6, 62, 8, 6, 1, 7, 1, 7, 5, 7, 66, 8, 7, 10, 7, 12, 7, 69, 9, 7, 1, 8, 1, 8, 3, 8, 73, 8, 8, 1, 8, 1, 8, 1, 8, 3, 8, 78, 8, 8, 1, 8, 5, 8, 81, 8, 8, 10, 8, 12, 8, 84, 9, 8, 1, 8, 1, 8, 1, 9, 1, 9, 3, 9, 90, 8, 9, 1, 10, 1, 10, 1, 11, 1, 11, 3, 11, 96, 8, 11, 1, 12, 1, 12, 1, 12, 0, 0, 13, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 0, 2, 1, 0, 1, 2, 1, 0, 4, 7, 98, 0, 26, 1, 0, 0, 0, 2, 28, 1, 0, 0, 0, 4, 37, 1, 0, 0, 0, 6, 40, 1, 0, 0, 0, 8, 51, 1, 0, 0, 0, 10, 53, 1, 0, 0, 0, 12, 57, 1, 0, 0, 0, 14, 63, 1, 0, 0, 0, 16, 70, 1, 0, 0, 0, 18, 89, 1, 0, 0, 0, 20, 91, 1, 0, 0, 0, 22, 95, 1, 0, 0, 0, 24, 97, 1, 0, 0, 0, 26, 27, 3, 2, 1, 0, 27, 1, 1, 0, 0, 0, 28, 34, 3, 6, 3, 0, 29, 30, 3, 4, 2, 0, 30, 31, 3, 6, 3, 0, 31, 33, 1, 0, 0, 0, 32, 29, 1, 0, 0, 0, 33, 36, 1, 0, 0, 0, 34, 32, 1, 0, 0, 0, 34, 35, 1, 0, 0, 0, 35, 3, 1, 0, 0, 0, 36, 34, 1, 0, 0, 0, 37, 38, 7, 0, 0, 0, 38, 5, 1, 0, 0, 0, 39, 41, 5, 3, 0, 0, 40, 39, 1, 0, 0, 0, 40, 41, 1, 0, 0, 0, 41, 42, 1, 0, 0, 0, 42, 43, 3, 8, 4, 0, 43, 7, 1, 0, 0, 0, 44, 45, 5, 9, 0, 0, 45, 46, 3, 0, 0, 0, 46, 47, 5, 10, 0, 0, 47, 52, 1, 0, 0, 0, 48, 52, 3, 10, 5, 0, 49, 52, 3, 12, 6, 0, 50, 52, 3, 14, 7, 0, 51, 44, 1, 0, 0, 0, 51, 48, 1, 0, 0, 0, 51, 49, 1, 0, 0, 0, 51, 50, 1, 0, 0, 0, 52, 9, 1, 0, 0, 0, 53, 54, 3, 20, 10, 0, 54, 55, 3, 24, 12, 0, 55, 56, 3, 22, 11, 0, 56, 11, 1, 0, 0, 0, 57, 58, 3, 20, 10, 0, 58, 61, 5, 8, 0, 0, 59, 62, 3, 22, 11, 0, 60, 62, 3, 16, 8, 0, 61, 59, 1, 0, 0, 0, 61, 60, 1, 0, 0, 0, 62, 13, 1, 0, 0, 0, 63, 67, 5, 12, 0, 0, 64, 66, 5, 12, 0, 0, 65, 64, 1, 0, 0, 0, 66, 69, 1, 0, 0, 0, 67, 65, 1, 0, 0, 0, 67, 68, 1, 0, 0, 0, 68, 15, 1, 0, 0, 0, 69, 67, 1, 0, 0, 0, 70, 72, 5, 9, 0, 0, 71, 73, 5, 3, 0, 0, 72, 71, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 74, 1, 0, 0, 0, 74, 82, 3, 18, 9, 0, 75, 77, 7, 0, 0, 0, 76, 78, 5, 3, 0, 0, 77, 76, 1, 0, 0, 0, 77, 78, 1, 0, 0, 0, 78, 79, 1, 0, 0, 0, 79, 81, 3, 18, 9, 0, 80, 75, 1, 0, 0, 0, 81, 84, 1, 0, 0, 0, 82, 80, 1, 0, 0, 0, 82, 83, 1, 0, 0, 0, 83, 85, 1, 0, 0, 0, 84, 82, 1, 0, 0, 0, 85, 86, 5, 10, 0, 0, 86, 17, 1, 0, 0, 0, 87, 90, 3, 16, 8, 0, 88, 90, 3, 22, 11, 0, 89, 87, 1, 0, 0, 0, 89, 88, 1, 0, 0, 0, 90, 19, 1, 0, 0, 0, 91, 92, 5, 12, 0, 0, 92, 21, 1, 0, 0, 0, 93, 96, 5, 11, 0, 0, 94, 96, 3, 14, 7, 0, 95, 93, 1, 0, 0, 0, 95, 94, 1, 0, 0, 0, 96, 23, 1, 0, 0, 0, 97, 98, 7, 1, 0, 0, 98, 25, 1, 0, 0, 0, 10, 34, 40, 51, 61, 67, 72, 77, 82, 89, 95] \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.java b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.java deleted file mode 100644 index c55b54ae7a0f..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.java +++ /dev/null @@ -1,828 +0,0 @@ -// Generated from /Users/paulstn/Documents/opensearch-2.15.0/OpenSearch-Dashboards/src/plugins/data/public/antlr/dql/grammar/DQLParser.g4 by ANTLR 4.13.1 -import org.antlr.v4.runtime.atn.*; -import org.antlr.v4.runtime.dfa.DFA; -import org.antlr.v4.runtime.*; -import org.antlr.v4.runtime.misc.*; -import org.antlr.v4.runtime.tree.*; -import java.util.List; -import java.util.Iterator; -import java.util.ArrayList; - -@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"}) -public class DQLParser extends Parser { - static { RuntimeMetaData.checkVersion("4.13.1", RuntimeMetaData.VERSION); } - - protected static final DFA[] _decisionToDFA; - protected static final PredictionContextCache _sharedContextCache = - new PredictionContextCache(); - public static final int - OR=1, AND=2, NOT=3, GT=4, LT=5, GE=6, LE=7, EQ=8, LPAREN=9, RPAREN=10, - PHRASE=11, ID=12, WS=13; - public static final int - RULE_query = 0, RULE_operatorExpression = 1, RULE_booleanOperator = 2, - RULE_notExpression = 3, RULE_primaryExpression = 4, RULE_comparisonExpression = 5, - RULE_keyValueExpression = 6, RULE_tokenSearch = 7, RULE_groupExpression = 8, - RULE_groupContent = 9, RULE_field = 10, RULE_value = 11, RULE_comparisonOperator = 12; - private static String[] makeRuleNames() { - return new String[] { - "query", "operatorExpression", "booleanOperator", "notExpression", "primaryExpression", - "comparisonExpression", "keyValueExpression", "tokenSearch", "groupExpression", - "groupContent", "field", "value", "comparisonOperator" - }; - } - public static final String[] ruleNames = makeRuleNames(); - - private static String[] makeLiteralNames() { - return new String[] { - null, null, null, null, "'>'", "'<'", "'>='", "'<='", "':'", "'('", "')'" - }; - } - private static final String[] _LITERAL_NAMES = makeLiteralNames(); - private static String[] makeSymbolicNames() { - return new String[] { - null, "OR", "AND", "NOT", "GT", "LT", "GE", "LE", "EQ", "LPAREN", "RPAREN", - "PHRASE", "ID", "WS" - }; - } - private static final String[] _SYMBOLIC_NAMES = makeSymbolicNames(); - public static final Vocabulary VOCABULARY = new VocabularyImpl(_LITERAL_NAMES, _SYMBOLIC_NAMES); - - /** - * @deprecated Use {@link #VOCABULARY} instead. - */ - @Deprecated - public static final String[] tokenNames; - static { - tokenNames = new String[_SYMBOLIC_NAMES.length]; - for (int i = 0; i < tokenNames.length; i++) { - tokenNames[i] = VOCABULARY.getLiteralName(i); - if (tokenNames[i] == null) { - tokenNames[i] = VOCABULARY.getSymbolicName(i); - } - - if (tokenNames[i] == null) { - tokenNames[i] = ""; - } - } - } - - @Override - @Deprecated - public String[] getTokenNames() { - return tokenNames; - } - - @Override - - public Vocabulary getVocabulary() { - return VOCABULARY; - } - - @Override - public String getGrammarFileName() { return "DQLParser.g4"; } - - @Override - public String[] getRuleNames() { return ruleNames; } - - @Override - public String getSerializedATN() { return _serializedATN; } - - @Override - public ATN getATN() { return _ATN; } - - public DQLParser(TokenStream input) { - super(input); - _interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache); - } - - @SuppressWarnings("CheckReturnValue") - public static class QueryContext extends ParserRuleContext { - public OperatorExpressionContext operatorExpression() { - return getRuleContext(OperatorExpressionContext.class,0); - } - public QueryContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_query; } - } - - public final QueryContext query() throws RecognitionException { - QueryContext _localctx = new QueryContext(_ctx, getState()); - enterRule(_localctx, 0, RULE_query); - try { - enterOuterAlt(_localctx, 1); - { - setState(26); - operatorExpression(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class OperatorExpressionContext extends ParserRuleContext { - public List notExpression() { - return getRuleContexts(NotExpressionContext.class); - } - public NotExpressionContext notExpression(int i) { - return getRuleContext(NotExpressionContext.class,i); - } - public List booleanOperator() { - return getRuleContexts(BooleanOperatorContext.class); - } - public BooleanOperatorContext booleanOperator(int i) { - return getRuleContext(BooleanOperatorContext.class,i); - } - public OperatorExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_operatorExpression; } - } - - public final OperatorExpressionContext operatorExpression() throws RecognitionException { - OperatorExpressionContext _localctx = new OperatorExpressionContext(_ctx, getState()); - enterRule(_localctx, 2, RULE_operatorExpression); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(28); - notExpression(); - setState(34); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==OR || _la==AND) { - { - { - setState(29); - booleanOperator(); - setState(30); - notExpression(); - } - } - setState(36); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class BooleanOperatorContext extends ParserRuleContext { - public TerminalNode OR() { return getToken(DQLParser.OR, 0); } - public TerminalNode AND() { return getToken(DQLParser.AND, 0); } - public BooleanOperatorContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_booleanOperator; } - } - - public final BooleanOperatorContext booleanOperator() throws RecognitionException { - BooleanOperatorContext _localctx = new BooleanOperatorContext(_ctx, getState()); - enterRule(_localctx, 4, RULE_booleanOperator); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(37); - _la = _input.LA(1); - if ( !(_la==OR || _la==AND) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class NotExpressionContext extends ParserRuleContext { - public PrimaryExpressionContext primaryExpression() { - return getRuleContext(PrimaryExpressionContext.class,0); - } - public TerminalNode NOT() { return getToken(DQLParser.NOT, 0); } - public NotExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_notExpression; } - } - - public final NotExpressionContext notExpression() throws RecognitionException { - NotExpressionContext _localctx = new NotExpressionContext(_ctx, getState()); - enterRule(_localctx, 6, RULE_notExpression); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(40); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==NOT) { - { - setState(39); - match(NOT); - } - } - - setState(42); - primaryExpression(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class PrimaryExpressionContext extends ParserRuleContext { - public TerminalNode LPAREN() { return getToken(DQLParser.LPAREN, 0); } - public QueryContext query() { - return getRuleContext(QueryContext.class,0); - } - public TerminalNode RPAREN() { return getToken(DQLParser.RPAREN, 0); } - public ComparisonExpressionContext comparisonExpression() { - return getRuleContext(ComparisonExpressionContext.class,0); - } - public KeyValueExpressionContext keyValueExpression() { - return getRuleContext(KeyValueExpressionContext.class,0); - } - public TokenSearchContext tokenSearch() { - return getRuleContext(TokenSearchContext.class,0); - } - public PrimaryExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_primaryExpression; } - } - - public final PrimaryExpressionContext primaryExpression() throws RecognitionException { - PrimaryExpressionContext _localctx = new PrimaryExpressionContext(_ctx, getState()); - enterRule(_localctx, 8, RULE_primaryExpression); - try { - setState(51); - _errHandler.sync(this); - switch ( getInterpreter().adaptivePredict(_input,2,_ctx) ) { - case 1: - enterOuterAlt(_localctx, 1); - { - setState(44); - match(LPAREN); - setState(45); - query(); - setState(46); - match(RPAREN); - } - break; - case 2: - enterOuterAlt(_localctx, 2); - { - setState(48); - comparisonExpression(); - } - break; - case 3: - enterOuterAlt(_localctx, 3); - { - setState(49); - keyValueExpression(); - } - break; - case 4: - enterOuterAlt(_localctx, 4); - { - setState(50); - tokenSearch(); - } - break; - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class ComparisonExpressionContext extends ParserRuleContext { - public FieldContext field() { - return getRuleContext(FieldContext.class,0); - } - public ComparisonOperatorContext comparisonOperator() { - return getRuleContext(ComparisonOperatorContext.class,0); - } - public ValueContext value() { - return getRuleContext(ValueContext.class,0); - } - public ComparisonExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_comparisonExpression; } - } - - public final ComparisonExpressionContext comparisonExpression() throws RecognitionException { - ComparisonExpressionContext _localctx = new ComparisonExpressionContext(_ctx, getState()); - enterRule(_localctx, 10, RULE_comparisonExpression); - try { - enterOuterAlt(_localctx, 1); - { - setState(53); - field(); - setState(54); - comparisonOperator(); - setState(55); - value(); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class KeyValueExpressionContext extends ParserRuleContext { - public FieldContext field() { - return getRuleContext(FieldContext.class,0); - } - public TerminalNode EQ() { return getToken(DQLParser.EQ, 0); } - public ValueContext value() { - return getRuleContext(ValueContext.class,0); - } - public GroupExpressionContext groupExpression() { - return getRuleContext(GroupExpressionContext.class,0); - } - public KeyValueExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_keyValueExpression; } - } - - public final KeyValueExpressionContext keyValueExpression() throws RecognitionException { - KeyValueExpressionContext _localctx = new KeyValueExpressionContext(_ctx, getState()); - enterRule(_localctx, 12, RULE_keyValueExpression); - try { - enterOuterAlt(_localctx, 1); - { - setState(57); - field(); - setState(58); - match(EQ); - setState(61); - _errHandler.sync(this); - switch (_input.LA(1)) { - case PHRASE: - case ID: - { - setState(59); - value(); - } - break; - case LPAREN: - { - setState(60); - groupExpression(); - } - break; - default: - throw new NoViableAltException(this); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class TokenSearchContext extends ParserRuleContext { - public List ID() { return getTokens(DQLParser.ID); } - public TerminalNode ID(int i) { - return getToken(DQLParser.ID, i); - } - public TokenSearchContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_tokenSearch; } - } - - public final TokenSearchContext tokenSearch() throws RecognitionException { - TokenSearchContext _localctx = new TokenSearchContext(_ctx, getState()); - enterRule(_localctx, 14, RULE_tokenSearch); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(63); - match(ID); - setState(67); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==ID) { - { - { - setState(64); - match(ID); - } - } - setState(69); - _errHandler.sync(this); - _la = _input.LA(1); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class GroupExpressionContext extends ParserRuleContext { - public TerminalNode LPAREN() { return getToken(DQLParser.LPAREN, 0); } - public List groupContent() { - return getRuleContexts(GroupContentContext.class); - } - public GroupContentContext groupContent(int i) { - return getRuleContext(GroupContentContext.class,i); - } - public TerminalNode RPAREN() { return getToken(DQLParser.RPAREN, 0); } - public List NOT() { return getTokens(DQLParser.NOT); } - public TerminalNode NOT(int i) { - return getToken(DQLParser.NOT, i); - } - public List OR() { return getTokens(DQLParser.OR); } - public TerminalNode OR(int i) { - return getToken(DQLParser.OR, i); - } - public List AND() { return getTokens(DQLParser.AND); } - public TerminalNode AND(int i) { - return getToken(DQLParser.AND, i); - } - public GroupExpressionContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_groupExpression; } - } - - public final GroupExpressionContext groupExpression() throws RecognitionException { - GroupExpressionContext _localctx = new GroupExpressionContext(_ctx, getState()); - enterRule(_localctx, 16, RULE_groupExpression); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(70); - match(LPAREN); - setState(72); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==NOT) { - { - setState(71); - match(NOT); - } - } - - setState(74); - groupContent(); - setState(82); - _errHandler.sync(this); - _la = _input.LA(1); - while (_la==OR || _la==AND) { - { - { - setState(75); - _la = _input.LA(1); - if ( !(_la==OR || _la==AND) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - setState(77); - _errHandler.sync(this); - _la = _input.LA(1); - if (_la==NOT) { - { - setState(76); - match(NOT); - } - } - - setState(79); - groupContent(); - } - } - setState(84); - _errHandler.sync(this); - _la = _input.LA(1); - } - setState(85); - match(RPAREN); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class GroupContentContext extends ParserRuleContext { - public GroupExpressionContext groupExpression() { - return getRuleContext(GroupExpressionContext.class,0); - } - public ValueContext value() { - return getRuleContext(ValueContext.class,0); - } - public GroupContentContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_groupContent; } - } - - public final GroupContentContext groupContent() throws RecognitionException { - GroupContentContext _localctx = new GroupContentContext(_ctx, getState()); - enterRule(_localctx, 18, RULE_groupContent); - try { - setState(89); - _errHandler.sync(this); - switch (_input.LA(1)) { - case LPAREN: - enterOuterAlt(_localctx, 1); - { - setState(87); - groupExpression(); - } - break; - case PHRASE: - case ID: - enterOuterAlt(_localctx, 2); - { - setState(88); - value(); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class FieldContext extends ParserRuleContext { - public TerminalNode ID() { return getToken(DQLParser.ID, 0); } - public FieldContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_field; } - } - - public final FieldContext field() throws RecognitionException { - FieldContext _localctx = new FieldContext(_ctx, getState()); - enterRule(_localctx, 20, RULE_field); - try { - enterOuterAlt(_localctx, 1); - { - setState(91); - match(ID); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class ValueContext extends ParserRuleContext { - public TerminalNode PHRASE() { return getToken(DQLParser.PHRASE, 0); } - public TokenSearchContext tokenSearch() { - return getRuleContext(TokenSearchContext.class,0); - } - public ValueContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_value; } - } - - public final ValueContext value() throws RecognitionException { - ValueContext _localctx = new ValueContext(_ctx, getState()); - enterRule(_localctx, 22, RULE_value); - try { - setState(95); - _errHandler.sync(this); - switch (_input.LA(1)) { - case PHRASE: - enterOuterAlt(_localctx, 1); - { - setState(93); - match(PHRASE); - } - break; - case ID: - enterOuterAlt(_localctx, 2); - { - setState(94); - tokenSearch(); - } - break; - default: - throw new NoViableAltException(this); - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - @SuppressWarnings("CheckReturnValue") - public static class ComparisonOperatorContext extends ParserRuleContext { - public TerminalNode GT() { return getToken(DQLParser.GT, 0); } - public TerminalNode LT() { return getToken(DQLParser.LT, 0); } - public TerminalNode GE() { return getToken(DQLParser.GE, 0); } - public TerminalNode LE() { return getToken(DQLParser.LE, 0); } - public ComparisonOperatorContext(ParserRuleContext parent, int invokingState) { - super(parent, invokingState); - } - @Override public int getRuleIndex() { return RULE_comparisonOperator; } - } - - public final ComparisonOperatorContext comparisonOperator() throws RecognitionException { - ComparisonOperatorContext _localctx = new ComparisonOperatorContext(_ctx, getState()); - enterRule(_localctx, 24, RULE_comparisonOperator); - int _la; - try { - enterOuterAlt(_localctx, 1); - { - setState(97); - _la = _input.LA(1); - if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & 240L) != 0)) ) { - _errHandler.recoverInline(this); - } - else { - if ( _input.LA(1)==Token.EOF ) matchedEOF = true; - _errHandler.reportMatch(this); - consume(); - } - } - } - catch (RecognitionException re) { - _localctx.exception = re; - _errHandler.reportError(this, re); - _errHandler.recover(this, re); - } - finally { - exitRule(); - } - return _localctx; - } - - public static final String _serializedATN = - "\u0004\u0001\rd\u0002\u0000\u0007\u0000\u0002\u0001\u0007\u0001\u0002"+ - "\u0002\u0007\u0002\u0002\u0003\u0007\u0003\u0002\u0004\u0007\u0004\u0002"+ - "\u0005\u0007\u0005\u0002\u0006\u0007\u0006\u0002\u0007\u0007\u0007\u0002"+ - "\b\u0007\b\u0002\t\u0007\t\u0002\n\u0007\n\u0002\u000b\u0007\u000b\u0002"+ - "\f\u0007\f\u0001\u0000\u0001\u0000\u0001\u0001\u0001\u0001\u0001\u0001"+ - "\u0001\u0001\u0005\u0001!\b\u0001\n\u0001\f\u0001$\t\u0001\u0001\u0002"+ - "\u0001\u0002\u0001\u0003\u0003\u0003)\b\u0003\u0001\u0003\u0001\u0003"+ - "\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004\u0001\u0004"+ - "\u0001\u0004\u0003\u00044\b\u0004\u0001\u0005\u0001\u0005\u0001\u0005"+ - "\u0001\u0005\u0001\u0006\u0001\u0006\u0001\u0006\u0001\u0006\u0003\u0006"+ - ">\b\u0006\u0001\u0007\u0001\u0007\u0005\u0007B\b\u0007\n\u0007\f\u0007"+ - "E\t\u0007\u0001\b\u0001\b\u0003\bI\b\b\u0001\b\u0001\b\u0001\b\u0003\b"+ - "N\b\b\u0001\b\u0005\bQ\b\b\n\b\f\bT\t\b\u0001\b\u0001\b\u0001\t\u0001"+ - "\t\u0003\tZ\b\t\u0001\n\u0001\n\u0001\u000b\u0001\u000b\u0003\u000b`\b"+ - "\u000b\u0001\f\u0001\f\u0001\f\u0000\u0000\r\u0000\u0002\u0004\u0006\b"+ - "\n\f\u000e\u0010\u0012\u0014\u0016\u0018\u0000\u0002\u0001\u0000\u0001"+ - "\u0002\u0001\u0000\u0004\u0007b\u0000\u001a\u0001\u0000\u0000\u0000\u0002"+ - "\u001c\u0001\u0000\u0000\u0000\u0004%\u0001\u0000\u0000\u0000\u0006(\u0001"+ - "\u0000\u0000\u0000\b3\u0001\u0000\u0000\u0000\n5\u0001\u0000\u0000\u0000"+ - "\f9\u0001\u0000\u0000\u0000\u000e?\u0001\u0000\u0000\u0000\u0010F\u0001"+ - "\u0000\u0000\u0000\u0012Y\u0001\u0000\u0000\u0000\u0014[\u0001\u0000\u0000"+ - "\u0000\u0016_\u0001\u0000\u0000\u0000\u0018a\u0001\u0000\u0000\u0000\u001a"+ - "\u001b\u0003\u0002\u0001\u0000\u001b\u0001\u0001\u0000\u0000\u0000\u001c"+ - "\"\u0003\u0006\u0003\u0000\u001d\u001e\u0003\u0004\u0002\u0000\u001e\u001f"+ - "\u0003\u0006\u0003\u0000\u001f!\u0001\u0000\u0000\u0000 \u001d\u0001\u0000"+ - "\u0000\u0000!$\u0001\u0000\u0000\u0000\" \u0001\u0000\u0000\u0000\"#\u0001"+ - "\u0000\u0000\u0000#\u0003\u0001\u0000\u0000\u0000$\"\u0001\u0000\u0000"+ - "\u0000%&\u0007\u0000\u0000\u0000&\u0005\u0001\u0000\u0000\u0000\')\u0005"+ - "\u0003\u0000\u0000(\'\u0001\u0000\u0000\u0000()\u0001\u0000\u0000\u0000"+ - ")*\u0001\u0000\u0000\u0000*+\u0003\b\u0004\u0000+\u0007\u0001\u0000\u0000"+ - "\u0000,-\u0005\t\u0000\u0000-.\u0003\u0000\u0000\u0000./\u0005\n\u0000"+ - "\u0000/4\u0001\u0000\u0000\u000004\u0003\n\u0005\u000014\u0003\f\u0006"+ - "\u000024\u0003\u000e\u0007\u00003,\u0001\u0000\u0000\u000030\u0001\u0000"+ - "\u0000\u000031\u0001\u0000\u0000\u000032\u0001\u0000\u0000\u00004\t\u0001"+ - "\u0000\u0000\u000056\u0003\u0014\n\u000067\u0003\u0018\f\u000078\u0003"+ - "\u0016\u000b\u00008\u000b\u0001\u0000\u0000\u00009:\u0003\u0014\n\u0000"+ - ":=\u0005\b\u0000\u0000;>\u0003\u0016\u000b\u0000<>\u0003\u0010\b\u0000"+ - "=;\u0001\u0000\u0000\u0000=<\u0001\u0000\u0000\u0000>\r\u0001\u0000\u0000"+ - "\u0000?C\u0005\f\u0000\u0000@B\u0005\f\u0000\u0000A@\u0001\u0000\u0000"+ - "\u0000BE\u0001\u0000\u0000\u0000CA\u0001\u0000\u0000\u0000CD\u0001\u0000"+ - "\u0000\u0000D\u000f\u0001\u0000\u0000\u0000EC\u0001\u0000\u0000\u0000"+ - "FH\u0005\t\u0000\u0000GI\u0005\u0003\u0000\u0000HG\u0001\u0000\u0000\u0000"+ - "HI\u0001\u0000\u0000\u0000IJ\u0001\u0000\u0000\u0000JR\u0003\u0012\t\u0000"+ - "KM\u0007\u0000\u0000\u0000LN\u0005\u0003\u0000\u0000ML\u0001\u0000\u0000"+ - "\u0000MN\u0001\u0000\u0000\u0000NO\u0001\u0000\u0000\u0000OQ\u0003\u0012"+ - "\t\u0000PK\u0001\u0000\u0000\u0000QT\u0001\u0000\u0000\u0000RP\u0001\u0000"+ - "\u0000\u0000RS\u0001\u0000\u0000\u0000SU\u0001\u0000\u0000\u0000TR\u0001"+ - "\u0000\u0000\u0000UV\u0005\n\u0000\u0000V\u0011\u0001\u0000\u0000\u0000"+ - "WZ\u0003\u0010\b\u0000XZ\u0003\u0016\u000b\u0000YW\u0001\u0000\u0000\u0000"+ - "YX\u0001\u0000\u0000\u0000Z\u0013\u0001\u0000\u0000\u0000[\\\u0005\f\u0000"+ - "\u0000\\\u0015\u0001\u0000\u0000\u0000]`\u0005\u000b\u0000\u0000^`\u0003"+ - "\u000e\u0007\u0000_]\u0001\u0000\u0000\u0000_^\u0001\u0000\u0000\u0000"+ - "`\u0017\u0001\u0000\u0000\u0000ab\u0007\u0001\u0000\u0000b\u0019\u0001"+ - "\u0000\u0000\u0000\n\"(3=CHMRY_"; - public static final ATN _ATN = - new ATNDeserializer().deserialize(_serializedATN.toCharArray()); - static { - _decisionToDFA = new DFA[_ATN.getNumberOfDecisions()]; - for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) { - _decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i); - } - } -} \ No newline at end of file diff --git a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.tokens b/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.tokens deleted file mode 100644 index d9da629fcca1..000000000000 --- a/src/plugins/data/public/antlr/dql/grammar/.antlr/DQLParser.tokens +++ /dev/null @@ -1,20 +0,0 @@ -OR=1 -AND=2 -NOT=3 -GT=4 -LT=5 -GE=6 -LE=7 -EQ=8 -LPAREN=9 -RPAREN=10 -PHRASE=11 -ID=12 -WS=13 -'>'=4 -'<'=5 -'>='=6 -'<='=7 -':'=8 -'('=9 -')'=10 diff --git a/src/plugins/data/public/antlr/shared/constants.ts b/src/plugins/data/public/antlr/shared/constants.ts deleted file mode 100644 index d0dbc0f70eac..000000000000 --- a/src/plugins/data/public/antlr/shared/constants.ts +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import { IndexPattern } from '../..'; - -export const testingIndex = ({ - title: 'opensearch_dashboards_sample_data_flights', - fields: [ - { - count: 0, - name: 'Carrier', - displayName: 'Carrier', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 2, - name: 'DestCityName', - displayName: 'DestCityName', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'DestCountry', - displayName: 'DestCountry', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'DestWeather', - displayName: 'DestWeather', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'DistanceMiles', - displayName: 'DistanceMiles', - type: 'number', - esTypes: ['float'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'FlightDelay', - displayName: 'FlightDelay', - type: 'boolean', - esTypes: ['boolean'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'FlightNum', - displayName: 'FlightNum', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: 'OriginWeather', - displayName: 'OriginWeather', - type: 'string', - esTypes: ['keyword'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: true, - subType: undefined, - }, - { - count: 0, - name: '_id', - displayName: '_id', - type: 'string', - esTypes: ['_id'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: false, - subType: undefined, - }, - { - count: 0, - name: '_index', - displayName: '_index', - type: 'string', - esTypes: ['_index'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: false, - subType: undefined, - }, - { - count: 0, - name: '_score', - displayName: '_score', - type: 'number', - scripted: false, - searchable: false, - aggregatable: false, - readFromDocValues: false, - subType: undefined, - }, - { - count: 0, - name: '_source', - displayName: '_source', - type: '_source', - esTypes: ['_source'], - scripted: false, - searchable: false, - aggregatable: false, - readFromDocValues: false, - subType: undefined, - }, - { - count: 0, - name: '_type', - displayName: '_type', - type: 'string', - esTypes: ['_type'], - scripted: false, - searchable: true, - aggregatable: true, - readFromDocValues: false, - subType: undefined, - }, - ], -} as unknown) as IndexPattern; - -export const booleanOperatorSuggestions = [ - { text: 'or', type: 17 }, - { text: 'and', type: 17 }, -]; - -export const notOperatorSuggestion = { text: 'not', type: 17 }; - -export const fieldNameSuggestions: Array<{ text: string; type: number; insertText?: string }> = [ - { text: 'Carrier', type: 3, insertText: 'Carrier: ' }, - { text: 'DestCityName', type: 3, insertText: 'DestCityName: ' }, - { text: 'DestCountry', type: 3, insertText: 'DestCountry: ' }, - { text: 'DestWeather', type: 3, insertText: 'DestWeather: ' }, - { text: 'DistanceMiles', type: 3, insertText: 'DistanceMiles: ' }, - { text: 'FlightDelay', type: 3, insertText: 'FlightDelay: ' }, - { text: 'FlightNum', type: 3, insertText: 'FlightNum: ' }, - { text: 'OriginWeather', type: 3, insertText: 'OriginWeather: ' }, - { text: '_id', type: 3, insertText: '_id: ' }, - { text: '_index', type: 3, insertText: '_index: ' }, - { text: '_score', type: 3, insertText: '_score: ' }, - { text: '_source', type: 3, insertText: '_source: ' }, - { text: '_type', type: 3, insertText: '_type: ' }, -]; - -export const fieldNameWithNotSuggestions = fieldNameSuggestions.concat(notOperatorSuggestion); diff --git a/src/plugins/data/public/autocomplete/autocomplete_service.ts b/src/plugins/data/public/autocomplete/autocomplete_service.ts index 4eec6f48079d..44e414581575 100644 --- a/src/plugins/data/public/autocomplete/autocomplete_service.ts +++ b/src/plugins/data/public/autocomplete/autocomplete_service.ts @@ -47,8 +47,6 @@ export class AutocompleteService { this.autocompleteConfig = autocomplete; } - private core: CoreSetup | undefined; - private readonly querySuggestionProviders: Map = new Map(); private getValueSuggestions?: ValueSuggestionsGetFn; @@ -63,7 +61,7 @@ export class AutocompleteService { const provider = this.querySuggestionProviders.get(language); if (provider) { - return provider({ core: this.core, ...args }); + return provider(args); } }; @@ -75,8 +73,6 @@ export class AutocompleteService { ? setupValueSuggestionProvider(core) : getEmptyValueSuggestions; - this.core = core; - return { addQuerySuggestionProvider: this.addQuerySuggestionProvider, diff --git a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts index 9b41fe8bb67f..636a4a1993b6 100644 --- a/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts +++ b/src/plugins/data/public/autocomplete/providers/query_suggestion_provider.ts @@ -29,7 +29,6 @@ */ import { monaco } from '@osd/monaco'; -import { CoreSetup } from 'opensearch-dashboards/public'; import { IFieldType, IndexPattern } from '../../../common/index_patterns'; import { IDataPluginServices } from '../../types'; @@ -56,7 +55,6 @@ export interface QuerySuggestionGetFnArgs { boolFilter?: any; position?: monaco.Position; services?: IDataPluginServices; - core?: CoreSetup; } /** @public **/ @@ -66,7 +64,7 @@ export interface QuerySuggestionBasic { end: number; start: number; text: string; - insertText: string; + insertText?: string; cursorIndex?: number; } diff --git a/src/plugins/data/public/ui/query_string_input/query_string_input.tsx b/src/plugins/data/public/ui/query_string_input/query_string_input.tsx index 62eca6bac579..b94c38d0f15e 100644 --- a/src/plugins/data/public/ui/query_string_input/query_string_input.tsx +++ b/src/plugins/data/public/ui/query_string_input/query_string_input.tsx @@ -47,7 +47,7 @@ import { import { FormattedMessage } from '@osd/i18n/react'; import { debounce, compact, isEqual, isFunction } from 'lodash'; import { Toast } from 'src/core/public'; -import { IDataPluginServices, IIndexPattern, Query } from '../..'; +import { IDataPluginServices, IIndexPattern, IndexPattern, Query } from '../..'; import { QuerySuggestion, QuerySuggestionTypes } from '../../autocomplete'; import { @@ -184,7 +184,7 @@ export default class QueryStringInputUI extends Component { const suggestions = (await this.services.data.autocomplete.getQuerySuggestions({ language, - indexPatterns, + indexPattern: indexPatterns[0] as IndexPattern, query: queryString, selectionStart, selectionEnd, diff --git a/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx b/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx index bc3a330c6081..8996297775c9 100644 --- a/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx +++ b/src/plugins/opensearch_dashboards_react/public/code_editor/code_editor.tsx @@ -38,14 +38,6 @@ import { LIGHT_THEME, DARK_THEME } from './editor_theme'; import './editor.scss'; -export interface LanguageSpecifiedConfiguration extends monaco.languages.LanguageConfiguration { - /** - * The language ID, meant to restrict the specified configuration for only this language. When - * not provided, will apply the language configuration for every language. - */ - language?: string; -} - export interface Props { /** Width of editor. Defaults to 100%. */ width?: string | number; @@ -65,37 +57,37 @@ export interface Props { /** * Options for the Monaco Code Editor * Documentation of options can be found here: - * https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html + * https://microsoft.github.io/monaco-editor/docs.html#interfaces/editor.IEditorConstructionOptions.html */ options?: monaco.editor.IEditorConstructionOptions; /** * Suggestion provider for autocompletion * Documentation for the provider can be found here: - * https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.completionitemprovider.html + * https://microsoft.github.io/monaco-editor/docs.html#interfaces/languages.CompletionItemProvider.html */ suggestionProvider?: monaco.languages.CompletionItemProvider; /** * Signature provider for function parameter info * Documentation for the provider can be found here: - * https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.signaturehelpprovider.html + * https://microsoft.github.io/monaco-editor/docs.html#interfaces/languages.SignatureHelpProvider.html */ signatureProvider?: monaco.languages.SignatureHelpProvider; /** * Hover provider for hover documentation * Documentation for the provider can be found here: - * https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.hoverprovider.html + * https://microsoft.github.io/monaco-editor/docs.html#interfaces/languages.HoverProvider.html */ hoverProvider?: monaco.languages.HoverProvider; /** * Language config provider for bracket * Documentation for the provider can be found here: - * https://microsoft.github.io/monaco-editor/api/interfaces/monaco.languages.languageconfiguration.html + * https://microsoft.github.io/monaco-editor/docs.html#interfaces/languages.LanguageConfiguration.html */ - languageConfiguration?: LanguageSpecifiedConfiguration; + languageConfiguration?: monaco.languages.LanguageConfiguration; /** * Function called before the editor is mounted in the view @@ -168,17 +160,7 @@ export class CodeEditor extends React.Component { } if (this.props.languageConfiguration) { - // if the language isn't specified or the language configuration specified language - // matches, use the configuration - if ( - !this.props.languageConfiguration.language || - this.props.languageConfiguration.language === languageId - ) { - monaco.languages.setLanguageConfiguration( - this.props.languageId, - this.props.languageConfiguration - ); - } + monaco.languages.setLanguageConfiguration(languageId, this.props.languageConfiguration); } });