Skip to content

Commit

Permalink
[Auto Suggest] PPL & SQL Value Suggestion (#8275) (#9244)
Browse files Browse the repository at this point in the history
(cherry picked from commit a7aeb76)

Signed-off-by: Paul Sebastian <paulstn@amazon.com>
Signed-off-by: Paul Sebastian <paulstn@dev-dsk-paulstn-2b-a4d3f011.us-west-2.amazon.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Paul Sebastian <paulstn@dev-dsk-paulstn-2b-a4d3f011.us-west-2.amazon.com>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
Co-authored-by: Sean Li <lnse@amazon.com>
  • Loading branch information
5 people authored Jan 31, 2025
1 parent 40dd6b8 commit bc517e4
Show file tree
Hide file tree
Showing 27 changed files with 2,717 additions and 1,116 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8275.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- Autocomplete Value Suggestion ([#8275](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8275))
2 changes: 2 additions & 0 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export const UI_SETTINGS = {
FILTERS_PINNED_BY_DEFAULT: 'filters:pinnedByDefault',
FILTERS_EDITOR_SUGGEST_VALUES: 'filterEditor:suggestValues',
QUERY_ENHANCEMENTS_ENABLED: 'query:enhancements:enabled',
QUERY_ENHANCEMENTS_SUGGEST_VALUES: 'query:enhancements:suggestValues',
QUERY_ENHANCEMENTS_SUGGEST_VALUES_LIMIT: 'query:enhancements:suggestValuesLimit',
QUERY_DATAFRAME_HYDRATION_STRATEGY: 'query:dataframe:hydrationStrategy',
SEARCH_QUERY_LANGUAGE_BLOCKLIST: 'search:queryLanguageBlocklist',
NEW_HOME_PAGE: 'home:useNewHomePage',
Expand Down
168 changes: 1 addition & 167 deletions src/plugins/data/public/antlr/dql/code_completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,176 +6,12 @@
import { monaco } from '@osd/monaco';
import { getSuggestions } from './code_completion';
import { DataPublicPluginStart, IDataPluginServices } from '../../types';
import { IndexPattern } from '../../index_patterns';
import { testingIndex } from '../shared/constants';

/**
* 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,
},
],
getFieldByName: jest.fn((fieldName: string) => {
return testingIndex.fields.find((field) => field.name === fieldName);
}),
} as unknown) as IndexPattern;

const booleanOperatorSuggestions = [
{ text: 'or', type: 11, detail: 'Operator', insertText: 'or ' },
{ text: 'and', type: 11, detail: 'Operator', insertText: 'and ' },
Expand Down Expand Up @@ -225,8 +61,6 @@ const allCarrierValueSuggestions = [
{ text: 'OpenSearch-Air', type: 13, detail: 'Value', insertText: '"OpenSearch-Air" ' },
];

const carrierWithNotSuggestions = allCarrierValueSuggestions.concat(notOperatorSuggestion);

const logCarrierValueSuggestion = [
{ text: 'Logstash Airways', type: 13, detail: 'Value', insertText: '"Logstash Airways" ' },
];
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/data/public/antlr/dql/code_completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { IndexPattern, IndexPatternField } from '../../index_patterns';
import { QuerySuggestion, QuerySuggestionGetFnArgs } from '../../autocomplete';
import { DQLParserVisitor } from './.generated/DQLParserVisitor';
import { IDataPluginServices } from '../..';
import { fetchFieldSuggestions } from '../shared/utils';
import { formatFieldsToSuggestions } from '../shared/utils';
import { SuggestionItemDetailsTags } from '../shared/constants';

const findCursorIndex = (
Expand Down Expand Up @@ -128,7 +128,7 @@ export const getSuggestions = async ({
// check to see if field rule is a candidate. if so, suggest field names
if (candidates.rules.has(DQLParser.RULE_field)) {
completions.push(
...fetchFieldSuggestions(indexPattern, (field: string) => {
...formatFieldsToSuggestions(indexPattern, (field: string) => {
const indexField = indexPattern.getFieldByName(field);
if (indexField && ['boolean', 'string'].includes(indexField.type)) {
return `${field} : `;
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit bc517e4

Please sign in to comment.