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

[Backport 2.x] [Auto Suggest] PPL & SQL Value Suggestion #9244

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
Loading