Skip to content

[ES|QL] Suggest only aggregation functions for SPARKLINE first argument - approach 1#268454

Closed
momovdg wants to merge 4 commits into
elastic:mainfrom
momovdg:esql-hint-kind-aggregation-filter
Closed

[ES|QL] Suggest only aggregation functions for SPARKLINE first argument - approach 1#268454
momovdg wants to merge 4 commits into
elastic:mainfrom
momovdg:esql-hint-kind-aggregation-filter

Conversation

@momovdg
Copy link
Copy Markdown
Contributor

@momovdg momovdg commented May 8, 2026

resolves: #265936

Summary

Problem

ES|QL's SPARKLINE function has a special first parameter that must always be an aggregation expression (e.g. AVG(bytes)). Elasticsearch signals this via hint: { kind: 'aggregation' } on the param definition, but Kibana's autocomplete ignored that hint entirely:

Inside STATS SPARKLINE(|, ...), all scalar functions (SUBSTRING, ABS, etc.) were suggested alongside aggregations, plus every field in the index — none of which are valid input.
The existing hint handler (buildSuggestionsFromHints) only dispatched on hint.entityType (used by inference_endpoint), so a kind-only hint was a no-op.

Fix

Surfaces the existing getAllFunctions({ type }) filter through the composite-suggestion path, gated on hint.kind:

  • ParameterHint.entityType → optional, since SPARKLINE's hint has only kind. Three callers that index parametersFromHintsResolvers[hint.entityType] are guarded.
  • New HINT_KIND_SUGGESTION_CONFIG map in empty_expression.ts translates hint.kind{ functionTypes, suppressFields }. Adding a kind = adding one entry; nothing else changes.
  • buildFieldAndFunctionSuggestions reads hint.kind and (a) skips addFields when suppressFields is set, (b) passes functionTypes to addFunctions.
  • functionTypes threaded through SuggestionBuilder.addFunctionsgetFunctionsSuggestionsgetAllFunctions, which already supports type filtering.
  • STATS expectsAggregation opt-out: buildCustomFilteringContext was adding every AGG name to functionsToIgnore (because isAggFunctionUsedAlready saw SPARKLINE itself in the AST). When the cursor's param has hint.kind === 'aggregation', the "no nested aggregations" rule does not apply — nesting is required, not forbidden.

Result for STATS SPARKLINE(|, ...): only AGG/TIME_SERIES_AGG functions are suggested, no fields. Self-recursion is still prevented (SPARKLINE itself stays in the ignore list).

5 production files + 3 caller guards + 1 SPARKLINE-on-STATS unit test.

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines
  • Review the backport guidelines and apply applicable backport:* labels.

@infra-vault-gh-plugin-prod
Copy link
Copy Markdown

🤖 Jobs for this PR can be triggered through checkboxes. 🚧

ℹ️ To trigger the CI, please tick the checkbox below 👇

  • Click to trigger kibana-pull-request for this PR!
  • Click to trigger kibana-deploy-project-from-pr for this PR!
  • Click to trigger kibana-deploy-cloud-from-pr for this PR!
  • Click to trigger kibana-entity-store-performance-from-pr for this PR!
  • Click to trigger kibana-storybooks-from-pr for this PR!

const results = hints.map(
(hint) =>
parametersFromHintsResolvers[hint.entityType]?.suggestionResolver?.(hint, ctx.context) ?? []
const results = hints.map((hint) =>
Copy link
Copy Markdown
Contributor Author

@momovdg momovdg May 8, 2026

Choose a reason for hiding this comment

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

some changes related to entityType are added because this property is now optional (based on the functions definitions).

...getFunctionsToIgnoreForStats(command, finalCommandArgIndex)
);

// The "no nested aggregations" rule applies unless the cursor's param
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this part is a little bit strange because now we are allowing nested aggregations (specific to this case only) compared to the initial requirement

@momovdg momovdg closed this May 11, 2026
@momovdg momovdg deleted the esql-hint-kind-aggregation-filter branch May 11, 2026 06:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ES|QL] Sparkline first argument should be an aggregation

1 participant