-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ES|QL] Separate
ENRICH
autocomplete routine (#211657)
## Summary Part of #195418 Gives `ENRICH` autocomplete logic its own home 🏡 ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios ### Identify risks - [ ] As with any refactor, there's a possibility this will introduce a regression in the behavior of commands. However, all automated tests are passing and I have tested the behavior manually and can detect no regression. --------- Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
- Loading branch information
1 parent
d291339
commit f2a9173
Showing
13 changed files
with
549 additions
and
376 deletions.
There are no files selected for viewing
142 changes: 142 additions & 0 deletions
142
...ql-validation-autocomplete/src/autocomplete/__tests__/autocomplete.command.enrich.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { camelCase } from 'lodash'; | ||
import { getFieldNamesByType, getPolicyFields, policies, setup } from './helpers'; | ||
|
||
describe('autocomplete.suggest', () => { | ||
describe('ENRICH', () => { | ||
const modes = ['any', 'coordinator', 'remote']; | ||
const expectedPolicyNameSuggestions = policies | ||
.map(({ name, suggestedAs }) => suggestedAs || name) | ||
.map((name) => `${name} `); | ||
|
||
let assertSuggestions: Awaited<ReturnType<typeof setup>>['assertSuggestions']; | ||
beforeEach(async () => { | ||
const setupResult = await setup(); | ||
assertSuggestions = setupResult.assertSuggestions; | ||
}); | ||
|
||
it('suggests policy names', async () => { | ||
await assertSuggestions(`from a | enrich /`, expectedPolicyNameSuggestions); | ||
await assertSuggestions(`from a | enrich po/`, expectedPolicyNameSuggestions); | ||
}); | ||
|
||
test('modes', async () => { | ||
await assertSuggestions( | ||
`from a | enrich _/`, | ||
modes.map((mode) => `_${mode}:$0`), | ||
{ triggerCharacter: '_' } | ||
); | ||
await assertSuggestions('from a | enrich _any: /', []); | ||
for (const mode of modes) { | ||
await assertSuggestions(`from a | enrich _${mode}:/`, expectedPolicyNameSuggestions, { | ||
triggerCharacter: ':', | ||
}); | ||
|
||
await assertSuggestions( | ||
`from a | enrich _${mode.toUpperCase()}:/`, | ||
expectedPolicyNameSuggestions, | ||
{ triggerCharacter: ':' } | ||
); | ||
|
||
await assertSuggestions( | ||
`from a | enrich _${camelCase(mode)}:/`, | ||
expectedPolicyNameSuggestions, | ||
{ triggerCharacter: ':' } | ||
); | ||
} | ||
}); | ||
|
||
it('suggests ON and WITH after policy name', async () => { | ||
await assertSuggestions(`from a | enrich policy /`, ['ON ', 'WITH ', '| ']); | ||
await assertSuggestions(`from a | enrich policy O/`, ['ON ', 'WITH ', '| ']); | ||
}); | ||
|
||
it('suggests fields after ON', async () => { | ||
await assertSuggestions( | ||
`from a | enrich policy on /`, | ||
getFieldNamesByType('any').map((v) => `${v} `) | ||
); | ||
await assertSuggestions( | ||
`from a | enrich policy on fi/`, | ||
getFieldNamesByType('any').map((v) => `${v} `) | ||
); | ||
}); | ||
|
||
describe('WITH', () => { | ||
it('suggests WITH after ON <field>', async () => { | ||
await assertSuggestions(`from a | enrich policy on field /`, ['WITH ', '| ']); | ||
}); | ||
|
||
it('suggests fields for new WITH clauses', async () => { | ||
await assertSuggestions(`from a | enrich policy on field with /`, [ | ||
'var0 = ', | ||
...getPolicyFields('policy').map((name) => ({ | ||
text: name, | ||
// Makes sure the suggestion menu isn't opened when a field is accepted | ||
command: undefined, | ||
})), | ||
]); | ||
await assertSuggestions(`from a | enrich policy on field with fi/`, [ | ||
'var0 = ', | ||
...getPolicyFields('policy'), | ||
]); | ||
await assertSuggestions(`from a | enrich policy on b with var0 = otherField, /`, [ | ||
'var1 = ', | ||
...getPolicyFields('policy'), | ||
]); | ||
await assertSuggestions(`from a | enrich policy on b with var0 = otherField, fi/`, [ | ||
'var1 = ', | ||
...getPolicyFields('policy'), | ||
]); | ||
}); | ||
|
||
test('waits to suggest fields until space', async () => { | ||
await assertSuggestions(`from a | enrich policy on b with var0 = otherField,/`, []); | ||
await assertSuggestions(`from a | enrich policy on b with/`, []); | ||
}); | ||
|
||
test('after first word', async () => { | ||
// not a recognized column name | ||
await assertSuggestions(`from a | enrich policy on b with var0 /`, ['= $0']); | ||
// recognized column name | ||
await assertSuggestions(`from a | enrich policy on b with otherField /`, [',', '| ']); | ||
}); | ||
|
||
test('suggests enrich fields after open assignment', async () => { | ||
await assertSuggestions(`from a | enrich policy on b with var0 = /`, [ | ||
...getPolicyFields('policy'), | ||
]); | ||
await assertSuggestions(`from a | enrich policy on b with var0 = fi/`, [ | ||
...getPolicyFields('policy'), | ||
]); | ||
await assertSuggestions(`from a | enrich policy on b with var0 = otherField, var1 = /`, [ | ||
...getPolicyFields('policy'), | ||
]); | ||
}); | ||
|
||
test('after complete clause', async () => { | ||
// works with escaped field names | ||
await assertSuggestions(`from a | enrich policy on b with var0 = \`otherField\` /`, [ | ||
',', | ||
'| ', | ||
]); | ||
await assertSuggestions(`from a | enrich policy on b with var0=otherField /`, [',', '| ']); | ||
await assertSuggestions(`from a | enrich policy on b with otherField /`, [',', '| ']); | ||
}); | ||
|
||
test('after user-defined column name', async () => { | ||
await assertSuggestions(`from a | enrich policy on b with var0 = otherField, var1 /`, [ | ||
'= $0', | ||
]); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.