Skip to content

Commit

Permalink
Add date histogram
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Aug 29, 2024
1 parent 3f5fa25 commit 4e3aa27
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
ESQLLiteral,
ESQLSingleAstItem,
} from '@kbn/esql-ast';
import { i18n } from '@kbn/i18n';
import { ESQL_NUMBER_TYPES, isNumericType } from '../shared/esql_types';
import type { EditorContext, SuggestionRawDefinition } from './types';
import {
Expand Down Expand Up @@ -1426,7 +1427,6 @@ async function getFunctionArgsSuggestions(
text: addCommaIf(shouldAddComma, suggestion.text),
}))
);

// could also be in stats (bucket) but our autocomplete is not great yet
if (
(getTypesFromParamDefs(typesToSuggestNext).includes('date') &&
Expand Down Expand Up @@ -1758,6 +1758,31 @@ async function getOptionArgsSuggestions(
);

if (option.name === 'by') {
// Add quick snippet for for stats ... by bucket(<>)
if (command.name === 'stats') {
suggestions.push({
label: i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.addDateHistogram',
{
defaultMessage: 'Add date histogram',
}
),
text: `BUCKET($0, 20, ?start, ?end)`,
asSnippet: true,
kind: 'Function',
detail: i18n.translate(
'kbn-esql-validation-autocomplete.esql.autocomplete.addDateHistogramDetail',
{
defaultMessage: 'Add date histogram using bucket()',
}
),
documentation: {
value: '',
},
sortText: '1A',
});
}

suggestions.push(
...(await getFieldsOrFunctionsSuggestions(
types[0] === 'column' ? ['any'] : types,
Expand Down

0 comments on commit 4e3aa27

Please sign in to comment.