Skip to content

feat(promql): math / trig scalar-transform functions (#45) - #81

Merged
zzylol merged 1 commit into
mainfrom
feat/math-trig-functions
Jul 3, 2026
Merged

zzylol merged 1 commit into
mainfrom
feat/math-trig-functions

Conversation

@zzylol

@zzylol zzylol commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

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, and pi() — 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 single AggIntent::Math variant carrying a MathFunc enum (~24 unary ops + clamp*/round scalar params), consistent with the counter-derivative (#44) / histogram-accessor (#43) pattern. pi() is the constant π → 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 step to 1, round(v, n) reads it.

Impact

Prometheus testdata corpus 1114 → 1183 lowered. Real alerts like floor(0.004 * http_requests{…}) and ln(v) > 0 now 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).

  • conformance section O; dropped clamp_max from unsupported_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

`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>
@zzylol

zzylol commented Jul 3, 2026

Copy link
Copy Markdown
Contributor Author

@milindsrivastava1997 FYI

@zzylol
zzylol merged commit cb9810a into main Jul 3, 2026
1 check passed
@zzylol
zzylol deleted the feat/math-trig-functions branch July 3, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromQL: math/trig scalar-transform functions (abs/ceil/floor/clamp/ln/…) unsupported

1 participant