AshDyan.Engine.TimeBucket (AshDyan v0.1.0)

Copy Markdown View Source

Helpers for time-bucket analysis.

  • label/2 computes the bucket label for the in-memory aggregation path used by the engine (works on any data layer, including ETS/Simple).
  • expr/2 is a reference helper that builds a Postgres date_trunc-style fragment. It is provided for a future SQL pushdown optimization; the engine currently aggregates time buckets in memory so the behaviour is identical across data layers.

Summary

Functions

Build a date_trunc-style expression for the given time field and bucket.

Compute a human-readable bucket label for an in-memory fallback (ETS/Simple).

Functions

expr(time_field, bucket)

@spec expr(atom(), AshDyan.time_bucket()) :: Macro.t()

Build a date_trunc-style expression for the given time field and bucket.

Reference helper for a future SQL pushdown optimization.

label(dt, bucket)

@spec label(DateTime.t() | NaiveDateTime.t() | Date.t() | nil, AshDyan.time_bucket()) ::
  String.t() | nil

Compute a human-readable bucket label for an in-memory fallback (ETS/Simple).

For :week we use the Monday of the ISO week. For :quarter we use the quarter start month.