Skip to content

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

Closed
momovdg wants to merge 5 commits into
elastic:mainfrom
momovdg:esql-hint-kind-resolver-dispatch
Closed

[ES|QL] Suggest only aggregation functions for SPARKLINE first argument - approach 2#268453
momovdg wants to merge 5 commits into
elastic:mainfrom
momovdg:esql-hint-kind-resolver-dispatch

Conversation

@momovdg
Copy link
Copy Markdown
Contributor

@momovdg momovdg commented May 8, 2026

part of: #265936

Summary

This PR addresses only the autocomplete functionality for the SPARKLINE function.

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

Extends the existing hint dispatcher to also key off hint.kind. The hint produces an exclusive suggestion set, so fields and other functions are skipped automatically — no flag plumbing needed (compared to this approach #268454):

  • ParameterHint.entityType → optional, with the three caller-side guards.
  • New kindBasedResolvers map in parameters_from_hints.ts, keyed by hint.kind. Adding a kind = adding one resolver entry.
  • aggregationKindResolver uses getAllFunctions({ type: [AGG, TIME_SERIES_AGG] }) then applies the same predicates the standard path uses (location, license, ignored, paramDefinitions return types) and appends , when hasMoreMandatoryArgs.
  • buildSuggestionsFromHints extended to fall back from the existing entityType dispatch to a hint.kind dispatch. Because this path lives inside tryExclusiveSuggestions, returning items short-circuits the composite path → fields are excluded by construction.
  • 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.

3 production files + 3 caller guards + 1 SPARKLINE unit test + 5 focused unit tests for the new resolver (return-type filter, ignored guard, comma handling, etc.).

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!

@momovdg momovdg self-assigned this May 12, 2026
@momovdg momovdg force-pushed the esql-hint-kind-resolver-dispatch branch from 194797f to ded68e7 Compare May 12, 2026 11:24
@momovdg momovdg closed this May 12, 2026
@momovdg momovdg deleted the esql-hint-kind-resolver-dispatch branch May 13, 2026 11:05
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.

1 participant