Repository navigation
feat(promql): math / trig scalar-transform functions (#45) - #81
Merged
Merged
Conversation
`abs`/`ceil`/`floor`/`exp`/`ln`/`log2`/`log10`/`sqrt`/`sgn`, the trig family
(`sin`…`atanh`), `deg`/`rad`, `clamp`/`clamp_min`/`clamp_max`, `round`, and
`pi()` parsed but were rejected. They now lower — ~81 corpus rejections, and
the Prometheus testdata corpus jumps 1114 → 1183 lowered.
Each element-wise transform is a per-series value map, lowered to a per-series
`Aggregate{[Math(f)]}` over the (instant) argument — one `AggIntent::Math`
variant carrying a `MathFunc` enum (the ~24 ops + `clamp*`/`round` scalar
params), consistent with the counter-derivative / histogram-accessor pattern.
`pi()` is the constant π, lowered to a `Scalar` leaf (#35).
- L3: `MathFunc` enum + `AggIntent::Math`; is_per_series()=true, float output.
- L2 `AggFunc::Math(MathFunc)` (reuses the ir MathFunc); converter maps it.
- Front end: `walk_math` + dispatch; `round(v)` defaults the step to 1.
Real alerts like `floor(0.004 * http_requests{…})` and `ln(v) > 0` now lower
(math + the #35 scalar operand). + conformance section O. Dropped `clamp_max`
from `unsupported_functions_are_rejected`. Full suite green; clippy clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
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.
Closes #45. The math/trig family —
abs/ceil/floor/exp/ln/log2/log10/sqrt/sgn, the trig set (sin…atanh),deg/rad,clamp/clamp_min/clamp_max,round, andpi()— parsed but were rejected.How
Each is a per-sample element-wise value transform, lowered to a per-series
Aggregate{[Math(f)]}over the (instant) argument — a singleAggIntent::Mathvariant carrying aMathFuncenum (~24 unary ops +clamp*/roundscalar params), consistent with the counter-derivative (#44) / histogram-accessor (#43) pattern.pi()is the constant π → aScalarleaf (#35).MathFuncenum +AggIntent::Math;is_per_series()=true, float output.AggFunc::Math(MathFunc)(reuses the irMathFunc); converter maps it.walk_math+ dispatch;round(v)defaults step to 1,round(v, n)reads it.Impact
Prometheus testdata corpus 1114 → 1183 lowered. Real alerts like
floor(0.004 * http_requests{…})andln(v) > 0now lower — math composed with the #35 scalar operand. Verified:abs(-1 * m),clamp_max(m, 5),round(v, 5),sqrt(rate(m[5m])),pi()→Scalar(π),sum by (job)(abs(v))(label-preserving).clamp_maxfromunsupported_functions_are_rejected. Full suite green (29 binaries), clippy clean.Note: models intent (which element-wise op); actual evaluation is an L4/runtime concern.
🤖 Generated with Claude Code