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

[ES|QL] open suggestions automatically in sources lists and ENRICH #191312

Merged
merged 26 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
22e9bc6
refactor integration suggestions in preparation
drewdaemon Aug 26, 2024
246600e
basic sources support
drewdaemon Aug 26, 2024
0bb1170
Support wild-cards in index name
drewdaemon Aug 26, 2024
dc69235
update some tests
drewdaemon Aug 26, 2024
050b040
Support METADATA field list
drewdaemon Aug 26, 2024
5376a57
fix up ENRICH experience
drewdaemon Aug 28, 2024
c298abb
include replacement range for policy names
drewdaemon Aug 28, 2024
b52fdc4
add replacement range for ENRICH
drewdaemon Aug 28, 2024
b18784a
fix suggestions for subsequent sources
drewdaemon Aug 28, 2024
102116b
update values test
drewdaemon Aug 28, 2024
797e4c9
test suite
drewdaemon Aug 28, 2024
f31bc05
test
drewdaemon Aug 28, 2024
e298e70
fix values suggestions
drewdaemon Aug 28, 2024
0caf743
restore metadata field, <suggest> behavior
drewdaemon Aug 28, 2024
cbaf4f2
update the lil util
drewdaemon Aug 29, 2024
a11d1fc
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Aug 29, 2024
9d22416
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Aug 30, 2024
0986780
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 3, 2024
c252f7e
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 5, 2024
fc48c2a
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 9, 2024
fbe444e
Merge branch 'main' of github.com:elastic/kibana into open-suggestion…
drewdaemon Sep 10, 2024
ff3fc5a
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 10, 2024
df61634
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 10, 2024
69085d8
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 13, 2024
fc67532
Merge branch 'main' into open-suggestions-for-sources
elasticmachine Sep 14, 2024
8569689
Merge branch 'main' into open-suggestions-for-sources
stratoula Sep 16, 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
2 changes: 1 addition & 1 deletion packages/kbn-esql-ast/src/ast_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,9 +405,9 @@ export function createSource(
index,
name: text,
sourceType: type,
text,
location: getPosition(ctx.start, ctx.stop),
incomplete: Boolean(ctx.exception || text === ''),
text: ctx?.getText(),
};
}

Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-esql-utils/src/utils/query_parsing_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function getIndexPatternFromESQLQuery(esql?: string) {
const sourceCommand = ast.find(({ name }) => ['from', 'metrics'].includes(name));
const args = (sourceCommand?.args ?? []) as ESQLSource[];
const indices = args.filter((arg) => arg.sourceType === 'index');
return indices?.map((index) => index.text).join(',');
return indices?.map((index) => index.name).join(',');
}

// For ES|QL we consider stats and keep transformational command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ const visibleIndices = indexes
.map(({ name, suggestedAs }) => suggestedAs || name)
.sort();

const addTrailingSpace = (strings: string[], predicate: (s: string) => boolean = (_s) => true) =>
strings.map((string) => (predicate(string) ? `${string} ` : string));

const metadataFields = [...METADATA_FIELDS].sort();

describe('autocomplete.suggest', () => {
Expand All @@ -37,17 +34,17 @@ describe('autocomplete.suggest', () => {
test('suggests visible indices on space', async () => {
const { assertSuggestions } = await setup();

await assertSuggestions('from /', addTrailingSpace(visibleIndices));
await assertSuggestions('FROM /', addTrailingSpace(visibleIndices));
await assertSuggestions('from /index', addTrailingSpace(visibleIndices));
await assertSuggestions('from /', visibleIndices);
await assertSuggestions('FROM /', visibleIndices);
await assertSuggestions('from /index', visibleIndices);
});

test('suggests visible indices on comma', async () => {
const { assertSuggestions } = await setup();

await assertSuggestions('FROM a,/', addTrailingSpace(visibleIndices));
await assertSuggestions('FROM a, /', addTrailingSpace(visibleIndices));
await assertSuggestions('from *,/', addTrailingSpace(visibleIndices));
await assertSuggestions('FROM a,/', visibleIndices);
await assertSuggestions('FROM a, /', visibleIndices);
await assertSuggestions('from *,/', visibleIndices);
});

test('can suggest integration data sources', async () => {
Expand All @@ -56,10 +53,7 @@ describe('autocomplete.suggest', () => {
.filter(({ hidden }) => !hidden)
.map(({ name, suggestedAs }) => suggestedAs || name)
.sort();
const expectedSuggestions = addTrailingSpace(
visibleDataSources,
(s) => !integrations.find(({ name }) => name === s)
);
const expectedSuggestions = visibleDataSources;
const { assertSuggestions, callbacks } = await setup();
const cb = {
...callbacks,
Expand All @@ -75,7 +69,7 @@ describe('autocomplete.suggest', () => {
});

describe('... METADATA <fields>', () => {
const metadataFieldsSandIndex = metadataFields.filter((field) => field !== '_index');
const metadataFieldsAndIndex = metadataFields.filter((field) => field !== '_index');

test('on <kbd>SPACE</kbd> without comma ",", suggests adding metadata', async () => {
const { assertSuggestions } = await setup();
Expand Down Expand Up @@ -103,8 +97,8 @@ describe('autocomplete.suggest', () => {
test('filters out already used metadata fields', async () => {
const { assertSuggestions } = await setup();

await assertSuggestions('from a, b [metadata _index, /]', metadataFieldsSandIndex);
await assertSuggestions('from a, b metadata _index, /', metadataFieldsSandIndex);
await assertSuggestions('from a, b [metadata _index, /]', metadataFieldsAndIndex);
await assertSuggestions('from a, b metadata _index, /', metadataFieldsAndIndex);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { groupingFunctionDefinitions } from '../../definitions/grouping';
import * as autocomplete from '../autocomplete';
import type { ESQLCallbacks } from '../../shared/types';
import type { EditorContext, SuggestionRawDefinition } from '../types';
import { TIME_SYSTEM_PARAMS } from '../factories';
import { TIME_SYSTEM_PARAMS, getSafeInsertText } from '../factories';
import { getFunctionSignatures } from '../../definitions/helpers';
import { ESQLRealField } from '../../validation/types';
import {
Expand Down Expand Up @@ -280,10 +280,7 @@ export function createCompletionContext(triggerCharacter?: string) {
export function getPolicyFields(policyName: string) {
return policies
.filter(({ name }) => name === policyName)
.flatMap(({ enrichFields }) =>
// ok, this is a bit of cheating as it's using the same logic as in the helper
enrichFields.map((field) => (/[^a-zA-Z\d_\.@]/.test(field) ? `\`${field}\`` : field))
);
.flatMap(({ enrichFields }) => enrichFields.map((field) => getSafeInsertText(field)));
Copy link
Member

@qn895 qn895 Sep 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we can probably use enrichFields.map(getSafeInsertText) here

}

export interface SuggestOptions {
Expand Down
Loading