Skip to content

PromQL: histogram_quantiles() and non-literal scalar k/φ parameters unsupported #109

Description

@zzylol

Summary

Two PromQL constructs parse cleanly but are rejected by the lowerer. Both are genuine coverage gaps rather than parser issues, so they are fixable entirely within crates/frontend-promql.

Corpus impact

30 rejections on origin/main @ 9fdd3d7 (of 322 total), plus ~21 more in the "arguably correct" bucket described under Notes.

Corrected 2026-07-09: figures re-measured on current main. The two counts below are unchanged; only the overall denominator moved (387 → 322) after the #40 offset/@ work landed.

Construct Rejections Error variant
histogram_quantiles(v, "label", φ…) 19 UnsupportedFunction
Non-literal scalar k / φ parameter 11 InvalidParameter

Examples

# histogram_quantiles — upstream experimental, variadic (up to 9 quantiles),
# returns one series per φ, tagged with the given label
histogram_quantiles(testhistogram3, "q", 0, 0.25, 0.5, 0.75, 1)

# non-literal k: the parameter is a scalar-valued *expression*, not a literal
topk(scalar(foo), http_requests)

Notes

  • histogram_quantiles is a real upstream function (promql/parser/functions.go:213, Experimental: true, Variadic: 9). It is effectively histogram_quantile fanned out over N quantiles with the results labelled — so it should decompose into the existing AggIntent::Quantile path once the fan-out is expressed. Related but distinct from PromQL: native-histogram accessor functions (histogram_*) unsupported #43 (histogram accessors) and PromQL: histogram_quantile classic-bucket vs sketch-able quantile is a structural heuristic — drive it from sample type/metadata #79 (classic-bucket vs sketch-able quantile), neither of which covers it.
  • The non-literal-k rejection comes from crates/frontend-promql/src/promql.rs:1560 (expected a numeric scalar, got {:?}). Today topk/bottomk/quantile require a literal scalar. topk(scalar(foo), v) supplies a scalar-valued subexpression, which is legal PromQL. Note the error message leaks a raw Discriminant(9) rather than naming the offending node — worth fixing regardless.
  • Possibly working as intended, flagged for a decision, not filed as part of this issue: ~22 further rejections come from out-of-domain constants that Prometheus accepts and answers with ±Inf/NaN plus a warn annotation, whereas we hard-error:
    histogram_quantile(1.001, testhistogram)   → InvalidParameter (Prometheus: +Inf + warn)
    quantile_over_time(-1, data[2m])           → InvalidParameter (Prometheus: -Inf + warn)
    topk(NaN, non_existent)                    → InvalidParameter
    
    (17 out-of-range quantile + 3 NaN k + 1 non-finite limit_ratio ratio = 21.)
    These originate from promql.rs:1617. For an optimizer IR, rejecting may well be the right call — but the divergence from PromQL semantics should be a conscious choice and ideally a documented one.
  • A further 5 rejections are bare string literals (("Foo")), rejected as UnsupportedFeature("bare string literal"). String-typed expressions have no vector semantics; almost certainly WAI.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestpromqlPromQL front-end lowering (L1→L2)

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions