Skip to content

Commit

Permalink
Fix grok and dissect behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed Sep 5, 2024
1 parent 866a6c9 commit c4cee0f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,23 @@ describe('autocomplete', () => {
`dissect keywordField ${constantPattern} |`,
];
for (const subExpression of subExpressions) {
testSuggestions(`from a | ${subExpression} grok /`, getFieldNamesByType(ESQL_STRING_TYPES));
testSuggestions(
`from a | ${subExpression} grok /`,
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions(`from a | ${subExpression} grok keywordField /`, [constantPattern], ' ');
testSuggestions(`from a | ${subExpression} grok keywordField ${constantPattern} /`, ['| ']);
}

testSuggestions(
'from a | grok /',
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions(
'from a | grok key/',
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions('from a | grok keywordField/', []);
});

describe('dissect', () => {
Expand All @@ -285,10 +298,9 @@ describe('autocomplete', () => {
`dissect keywordField ${constantPattern} append_separator = ":" |`,
];
for (const subExpression of subExpressions) {
// Unskip once https://github.com/elastic/kibana/issues/190070 is fixed
testSuggestions.skip(
testSuggestions(
`from a | ${subExpression} dissect /`,
getFieldNamesByType(ESQL_STRING_TYPES)
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions(`from a | ${subExpression} dissect keywordField /`, [constantPattern], ' ');
testSuggestions(
Expand All @@ -305,6 +317,16 @@ describe('autocomplete', () => {
['| ']
);
}

testSuggestions(
'from a | dissect /',
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions(
'from a | dissect key/',
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);
testSuggestions('from a | dissect keywordField/', []);
});

describe('sort', () => {
Expand Down Expand Up @@ -567,7 +589,10 @@ describe('autocomplete', () => {
]);

// DISSECT field
testSuggestions('FROM index1 | DISSECT b/', getFieldNamesByType(ESQL_STRING_TYPES));
testSuggestions(
'FROM index1 | DISSECT b/',
getFieldNamesByType(ESQL_STRING_TYPES).map((name) => `${name} `)
);

// DROP (first field)
testSuggestions('FROM index1 | DROP f/', getFieldNamesByType('any'));
Expand Down Expand Up @@ -599,7 +624,11 @@ describe('autocomplete', () => {
]);

// GROK field
testSuggestions('FROM index1 | GROK f/', getFieldNamesByType(ESQL_STRING_TYPES), undefined);
testSuggestions(
'FROM index1 | GROK f/',
getFieldNamesByType(ESQL_STRING_TYPES).map((field) => `${field} `),
undefined
);

// KEEP (first field)
testSuggestions('FROM index1 | KEEP f/', getFieldNamesByType('any'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ async function getExpressionSuggestionsByType(
// check if lastWord is an existing field
const column = getColumnByName(lastWord, references);
if (column) {
if (['grok', 'dissect'].includes(command.name)) {
return [];
}
// now we know that the user has already entered a column,
// so suggest comma and pipe
// const NON_ALPHANUMERIC_REGEXP = /[^a-zA-Z\d]/g;
Expand All @@ -734,6 +737,7 @@ async function getExpressionSuggestionsByType(
suggestions.push(
...fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
rangeToReplace,
}))
Expand All @@ -744,6 +748,7 @@ async function getExpressionSuggestionsByType(
suggestions.push(
...fieldSuggestions.map((suggestion) => ({
...suggestion,
text: suggestion.text + (['grok', 'dissect'].includes(command.name) ? ' ' : ''),
command: TRIGGER_SUGGESTION_COMMAND,
}))
);
Expand Down

0 comments on commit c4cee0f

Please sign in to comment.