Skip to content

[ES|QL] PromQL parser initial implementation#246552

Merged
vadimkibana merged 6 commits intoelastic:mainfrom
vadimkibana:promql-parser-8
Dec 17, 2025
Merged

[ES|QL] PromQL parser initial implementation#246552
vadimkibana merged 6 commits intoelastic:mainfrom
vadimkibana:promql-parser-8

Conversation

@vadimkibana
Copy link
Contributor

@vadimkibana vadimkibana commented Dec 16, 2025

Summary

Partially addresses #243932

This PR adds PromQL language parsing support to kbn-esql-ast. The parser is mostly complete with one known TODO in the CST-to-AST converter for SubqueryResolutionContext and NonReservedContext handling. Also, there might be some AST interface tweaks going forward, but overall the parser works.

Note: The PromQL ANTLR grammar we use, which is ported from Elasticsearch repo, does not exactly match the Prometheus PromQL language (some language features are missing, some implemented slightly differently).

The parser allows to provide offset option, which bumps all .location positions of AST nodes by that value. This will allow us to parse nested PromQL queries within ES|QL and set their .location correctly.

The PromQL AST nodes contain an extra dialect: 'promql' field, which helps to differentiate them from the ES|QL nodes.

Most AST nodes re-use the existing node shape from the ES|QL AST nodes (e.g. numbers, string, identifiers), however, other are specific for PromQL (function with grouping, selector, etc..), so they have their own interface and node type.

Testing

yarn test:jest src/platform/packages/shared/kbn-esql-ast/src/promql

Checklist

@vadimkibana vadimkibana marked this pull request as ready for review December 16, 2025 14:19
@vadimkibana vadimkibana requested a review from a team as a code owner December 16, 2025 14:19
@vadimkibana vadimkibana added review release_note:skip Skip the PR/issue when compiling release notes backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana Team:ESQL ES|QL related features in Kibana t// v9.4.0 labels Dec 16, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-esql (Team:ESQL)

@elasticmachine
Copy link
Contributor

elasticmachine commented Dec 16, 2025

💔 Build Failed

Failed CI Steps

History

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

Fascinating! This looks awesome! Thanks Vadim

@vadimkibana vadimkibana enabled auto-merge (squash) December 17, 2025 11:27
@vadimkibana vadimkibana added v9.3.0 and removed v9.4.0 labels Dec 17, 2025
@vadimkibana vadimkibana merged commit e8fa534 into elastic:main Dec 17, 2025
16 checks passed
mbondyra added a commit to mbondyra/kibana that referenced this pull request Dec 17, 2025
…donly

* commit 'bb1f55fa520b30ceb923af069ef403b24dcb1606': (52 commits)
  [CPS][Maps] Support CPS Picker in Maps  (elastic#246382)
  [APM] Migrate the Transaction Overview tests to Scout/Playwright/Component/API tests (elastic#245972)
  [Cases] Change nested field search to be case insensitive (elastic#246643)
  [ES|QL] PromQL parser initial implementation (elastic#246552)
  [Agent Builder] Adds keyboard shortcut and toggle behavior to AI Agent button (elastic#246659)
  Retry on "all shards failed" from ES (elastic#246533)
  [Streams] Test enable wired streams flow (elastic#246113)
  [Agent Builder] Fast-follow bugfixes for MCP Tool type  (elastic#246665)
  [Entity Store][API] Fix snake case on CRUD API List response (elastic#246003)
  [ResponseOps][Slack] Simplify channel configuration  (elastic#245423)
  Add Canonical Name Badge to Documentation (elastic#246647)
  [Streams] Add simulation filtering by conditions (elastic#245400)
  [o11y AI] Add `get_hosts` tool (elastic#246541)
  [agent builder] create_visualization: support heatmap and regionmap (elastic#246671)
  [AI Infra] Chat experience: Selection modal title change (elastic#246683)
  [Background search] Change polling behavior (elastic#244760)
  [ES|QL  ]  Common Lookup Join Fields Are Not Listed First (elastic#246582)
  Add missing `dynamic: false` (elastic#246685)
  [Metrics in Discover] Unskip metrics api test (elastic#246593)
  [ES|QL] Show next actions after simple field assignment in RERANK ON Clause (elastic#246676)
  ...
KodeRad pushed a commit to KodeRad/kibana that referenced this pull request Dec 17, 2025
## Summary

Partially addresses elastic#243932

This PR adds PromQL language parsing support to `kbn-esql-ast`. The
parser is mostly complete with one known TODO in the CST-to-AST
converter for `SubqueryResolutionContext` and `NonReservedContext`
handling. Also, there might be some AST interface tweaks going forward,
but overall the parser works.

Note: The PromQL ANTLR grammar we use, which is ported from
Elasticsearch repo, does not exactly match the Prometheus PromQL
language (some language features are missing, some implemented slightly
differently).

The parser allows to provide `offset` option, which bumps all
`.location` positions of AST nodes by that value. This will allow us to
parse nested PromQL queries within ES|QL and set their `.location`
correctly.

The PromQL AST nodes contain an extra `dialect: 'promql'` field, which
helps to differentiate them from the ES|QL nodes.

Most AST nodes re-use the existing node shape from the ES|QL AST nodes
(e.g. numbers, string, identifiers), however, other are specific for
PromQL (function with grouping, selector, etc..), so they have their own
interface and node type.

### Testing

```sh
yarn test:jest src/platform/packages/shared/kbn-esql-ast/src/promql
```


### 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

---------

Co-authored-by: Stratou <stratoula1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting Feature:ES|QL ES|QL related features in Kibana release_note:skip Skip the PR/issue when compiling release notes review Team:ESQL ES|QL related features in Kibana t// v9.3.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants