Skip to content

Cover PromQL special values in binary operators - #104485

Closed
BadLiveware wants to merge 51 commits into
ClickHouse:masterfrom
BadLiveware:split/promql-binary-special-values
Closed

BadLiveware wants to merge 51 commits into
ClickHouse:masterfrom
BadLiveware:split/promql-binary-special-values

Conversation

@BadLiveware

@BadLiveware BadLiveware commented May 9, 2026 •

Copy link
Copy Markdown

Adds deterministic Prometheus protocol coverage for already-supported binary operator behavior around +Inf, -Inf, and NaN inputs.

The cases document how Prometheus range results drop NaN samples for these expressions while preserving infinities through arithmetic and bool comparisons.

Split out from the integration draft #104271; shared base #104484.

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Not for changelog.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

BadLiveware added 13 commits May 9, 2026 13:52
Add the common PromQL compliance reporting and developer notes used by the follow-up TimeSeries PromQL lowering slices. Keep the parser compliance corpus expectation explicit for selectors Prometheus rejects.
Add focused Prometheus protocol tests for user-facing native lowering errors: unsupported-but-parseable functions and invalid date-function arity. These are semantic guardrails for clear errors, not broad coverage padding.
Add deterministic Prometheus protocol evaluation cases for already-supported binary operator behavior around +Inf, -Inf, and NaN inputs. These tests keep PR 2 test-only while documenting how Prometheus range results drop NaN samples for these expressions and preserve infinities through arithmetic and bool comparisons.
Avoid fork-local wording in the PromQL review base. These are ClickHouse PromQL regression cases and evidence requirements, not fork-specific artifacts.
Avoid fork-local wording in the PromQL review base. These are ClickHouse PromQL regression cases and evidence requirements, not fork-specific artifacts.
Remove the standalone native histogram discovery Markdown note from the PromQL split branches.
Remove the standalone native histogram discovery Markdown note from the PromQL split branches.
Remove downstream promshim-specific evidence and non-goal language from the native PromQL lowering README so the note stays focused on ClickHouse review guidance.
Remove downstream promshim-specific evidence and non-goal language from the native PromQL lowering README so the note stays focused on ClickHouse review guidance.
Rewrite the native PromQL lowering notes around external SQL-transpiler measurements. Document measured and mixed SQL patterns with target PromQL shapes, pseudocode, and the ClickHouse-side validation expected for in-tree changes.
Rewrite the native PromQL lowering notes around external SQL-transpiler measurements. Document measured and mixed SQL patterns with target PromQL shapes, pseudocode, and the ClickHouse-side validation expected for in-tree changes.
Replace external corpus row names with concrete PromQL expressions and query-range context in the native PromQL lowering notes.
Replace external corpus row names with concrete PromQL expressions and query-range context in the native PromQL lowering notes.
@alexey-milovidov alexey-milovidov added the can be tested Allows running workflows for external contributors label May 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [7a85785]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_llvm_coverage, ParallelReplicas, s3 storage, parallel) FAIL
02180_group_by_lowcardinality FAIL cidb
02345_implicit_transaction NOT_FAILED cidb
02435_rollback_cancelled_queries NOT_FAILED cidb
Stress test (arm_asan_ubsan) FAIL
Cannot start clickhouse-server FAIL cidb
Check failed FAIL cidb
libFuzzer tests FAIL
create_parser_fuzzer FAIL cidb

AI Review

Summary

This PR expands PromQL parser and integration coverage for selector-validation and special floating-point binary/comparison behavior, and adds detailed lowering notes. One previously reported reporting-classification issue is still live in test_compliance: operator detection is still lexeme-based for some scalar spellings, so failure buckets can be misrouted.

Findings

⚠️ Majors

  • [tests/integration/test_prometheus_protocols/test_compliance.py:638] _has_binary_operator still misclassifies some non-operator/operator forms (1e+3 is treated as binary because of exponent +, while foo - -1 is treated as non-binary). This continues to skew self-assurance failure routing by syntax spelling rather than PromQL operator tokens.
    Suggested fix: extend token handling for exponent signs and unary-minus RHS (or derive operator presence from parser tokens/AST instead of character scanning).
Final Verdict

Status: ⚠️ Request changes

Minimum required actions:

  1. Fix operator classification in _has_binary_operator for exponent-sign and unary-minus forms so category routing stays token-accurate.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 10, 2026
Match Prometheus parser behavior by requiring vector selectors to contain at
least one matcher that cannot match an empty label value. This prevents broad
selectors like `{job=~".*"}` or `{__name__=~".*"}` from silently selecting every
metric when the user likely intended an explicit non-empty constraint.

Users who intentionally want all real metrics can still use `{__name__=~".+"}`,
and empty-matching label matchers remain valid when combined with that explicit
metric-name matcher.
Deduplicate expanded compliance cases by query text before checking the
`should_fail` expectation. A query listed once as expected success and once as
expected failure is now reported as conflicting metadata instead of slipping
through as two separate cases.
Mirror the upstream PromQL compliance corpus for label transformation invalid
label-name cases. These cases should remain should-fail entries so ClickHouse
acceptance of invalid destination labels stays visible as a rejection mismatch
rather than being counted as expected coverage.
Do not stop selector validation after finding the first matcher that cannot match an empty label value. Later regex matchers still need syntax validation so equivalent selector reorderings cannot change parse validity.

Add parser regressions for invalid regex matchers after an implicit metric-name matcher and after explicit non-empty matchers.
Do not stop selector validation after finding the first matcher that cannot match an empty label value. Later regex matchers still need syntax validation so equivalent selector reorderings cannot change parse validity.

Add parser regressions for invalid regex matchers after an implicit metric-name matcher and after explicit non-empty matchers.
@vitlibar vitlibar self-assigned this May 13, 2026
BadLiveware and others added 10 commits May 15, 2026 07:45
Ignore string literals and selector matchers when routing compliance failures by query shape. This keeps report categories from treating label values or exponent signs as binary operators, and recognizes bare '<' and '>' comparisons.
Use the existing eps parameter when checking live Prometheus HTTP results against expected JSON, and compare ClickHouse HTTP output against the live Prometheus result. This keeps numeric drift bounded to eps while preserving exact shape, label, and timestamp checks.
Matcher validation intentionally turns malformed label regexes into PromQL parse errors. Construct RE2 with log_errors disabled so rejected selectors do not also emit internal RE2 error log lines on every parse attempt.
@clickhouse-gh

clickhouse-gh Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.10% 84.20% +0.10%
Functions 91.40% 91.40% +0.00%
Branches 76.50% 76.70% +0.20%

Changed lines: 99.23% (129/130) · Uncovered code

Full report · Diff report

Keep the PromQL parser, modifier, and selector fixes from the local matrix pass, but move the high-value regression coverage into the existing protocol and compliance suites instead of adding the standalone matrix harness to the PR branch.\n\nThis keeps fixed-time range evaluation covered through the existing evaluation tests and records the parser, matcher, timestamp-modifier, and sparse range cases in the shared compliance corpus.
Build (arm_tidy) flagged the vector-grid finalization predicate because one call cloned an AST pointer while another argument moved the same pointer. C++ argument evaluation order can make that a use-after-move.\n\nCreate separate AST nodes for the null and stale-marker checks so the generated predicate stays the same without relying on argument evaluation order.
Parse `@ start()` and `@ end()` as timestamp modifier variants instead of
rewriting the raw query text before parsing. This keeps label values and
regular expressions untouched while resolving symbolic bounds in the query
range planner.

Propagate symbolic `@` modifiers through the PromQL tree and SQL lowering so
instant selectors and range-vector functions bind to the query start or end
consistently with Prometheus.
The selector-matcher validation branch should not also introduce symbolic
`@ start()` and `@ end()` modifier parsing. Remove that parser/evaluation
feature from the base branch so the behavior can be reviewed independently.

Move the symbolic timestamp-modifier compliance cases out with the feature.
Keep the offset-only case here because it exercises existing modifier behavior.
Symbolic `@ start()` and `@ end()` modifiers need parser-level handling so
selectors, string literals, and regular expressions are not rewritten as raw
text. Remove the temporary text-substitution path from the base branch; the
symbolic modifier implementation belongs with the dedicated parser change.
Prometheus accepts `@ start()` and `@ end()` as timestamp modifiers that
bind to the query-range bounds, or to the instant evaluation time for an
instant query. Represent these forms in the PromQL tree instead of rewriting
raw query text, so matcher literals and regular expressions are preserved.

Resolve symbolic modifiers while computing node evaluation ranges and reuse
the existing fixed-evaluation-time lowering path for instant selectors and
range-vector functions. Add parser, evaluation, and compliance coverage for
both symbolic bounds.
@clickhouse-gh clickhouse-gh Bot added the manual approve Manual approve required to run CI label May 22, 2026
Exercise symbolic `@ start()` and `@ end()` modifiers together with
special-float binary vector operators. This keeps the downstream canary PR
useful for validating the intended stack, rather than only checking that the
modifier and binary-special test groups coexist independently.
@nikitamikhaylov nikitamikhaylov added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Aug 3, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Dear @BadLiveware, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

1 similar comment
@clickhouse-gh

clickhouse-gh Bot commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Dear @BadLiveware, this PR hasn't been updated for a while. Will you continue working on it? If not, please close it. Otherwise, ignore this message.

@vitlibar

vitlibar commented Nov 1, 2026

Copy link
Copy Markdown
Member

Superseded by #121099, #121098, #114558, #120849, #125937

@vitlibar vitlibar closed this Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... manual approve Manual approve required to run CI pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants