refactor(query-engine): split enable_topk into limiting vs formatting flags#391
Merged
milindsrivastava1997 merged 3 commits intoJun 6, 2026
Conversation
milindsrivastava1997
left a comment
Contributor
There was a problem hiding this comment.
Can you check if there are tests that exercise PromQL's topk behavior? both in terms of the semantics, as well as the extra output label that is inserted into the result? If those tests are not there, could you please add them (use main as a source for adding them), and then test them against this branch?
Apart from that, looks good
Collaborator
Author
|
Currently, there are no tests that exercise PromQL's topk behavior. Shall I add the test to the same PR? |
milindsrivastava1997
approved these changes
Jun 6, 2026
akanksha-akkihal
added a commit
that referenced
this pull request
Jun 6, 2026
… flags (#391) * split enable_topk into limiting vs formatting flags * add PromQL topk pipeline and Prometheus wire format tests * formatting
akanksha-akkihal
added a commit
that referenced
this pull request
Jun 6, 2026
… flags (#391) * split enable_topk into limiting vs formatting flags * add PromQL topk pipeline and Prometheus wire format tests * formatting
milindsrivastava1997
pushed a commit
that referenced
this pull request
Jun 6, 2026
* Support for SQL Top-K * Fomatting * refactor(query-engine): split enable_topk into limiting vs formatting flags (#391) * split enable_topk into limiting vs formatting flags * add PromQL topk pipeline and Prometheus wire format tests * formatting * Complete pipeline for SQL topK queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Split
enable_topkinto limiting vs formatting flagsBackground
Previously,
enable_topkwas responsible for two unrelated behaviors:__name__) in PromQL-style outputThis coupling worked for PromQL (which requires both behaviors), but it breaks SQL semantics.
SQL only needs top-k selection, not PromQL-style label formatting. With a single flag, it was impossible to express:
Problem
The original design conflated two independent concerns:
This caused SQL queries to unintentionally inherit PromQL formatting.
Solution: Split into two flags
We introduce two independent flags:
1.
enable_topk_limitingControls heap-based top-k selection:
2.
enable_topk_formattingControls PromQL-specific output formatting:
__name__)Resulting behavior
enable_topk_limitingenable_topk_formattingSubtle detail
Sorting remains enabled for
Statistic::Topkregardless of formatting.TL;DR
This change decouples:
from
This separation aligns the execution model with the fundamental difference between SQL and PromQL semantics.