Class TimeSeriesCollapseOperator

java.lang.Object
org.elasticsearch.compute.operator.HashAggregationOperator
org.elasticsearch.compute.operator.TimeSeriesCollapseOperator
All Implemented Interfaces:
Closeable, AutoCloseable, Operator, Releasable

public class TimeSeriesCollapseOperator extends HashAggregationOperator
Collapses expanded time-series rows into one multi-valued row per output series.

Groups are the output dimensions from the preceding aggregation. For each group this operator stores values by requested time step, then emits the steps in range order so the step and value multi-valued columns stay positionally aligned.

The collapse state is a dense grid of groupId x stepOrdinal flattened into parallel values and seen arrays:


 stepCount = 4
 steps     = [10, 20, 30, 40]

                 |        group 0        |        group 1        |        group 2        |
                 |-----------------------|-----------------------|-----------------------|
 stepOrdinal     |   0 |   1 |   2 |   3 |   0 |   1 |   2 |   3 |   0 |   1 |   2 |   3 |
 timestamp       |  10 |  20 |  30 |  40 |  10 |  20 |  30 |  40 |  10 |  20 |  30 |  40 |
 flat index      |   0 |   1 |   2 |   3 |   4 |   5 |   6 |   7 |   8 |   9 |  10 |  11 |

 values[]        | 1.2 |  -- | 3.4 |  -- |  -- | 8.1 |  -- | 8.4 | 5.0 |  -- |  -- |  -- |
 seen[]          |   1 |   0 |   1 |   0 |   0 |   1 |   0 |   1 |   1 |   0 |   0 |   0 |
 

The grouping hash maps dimension keys to the groupId slices:


 {host=h1, metric=cpu} -> group 0 -> flat indexes 0..3
 {host=h2, metric=cpu} -> group 1 -> flat indexes 4..7
 {host=h3, metric=mem} -> group 2 -> flat indexes 8..11
 

The value storage grows to the end of a group's slice when that group is first encountered, so observing group 1 grows the value array to at least flat index 7 + 1. The seen bitset still marks only the slots that actually received values.

The value column is ElementType.DOUBLE only for now (e.g. PROMQL scalar outputs).

Step semantics: step is a fixed millisecond interval and the operator assumes input timestamps fall on the uniform grid start, start + step, start + 2*step, ..., end. Calendar units (months, years) and timezone-aware steps that span DST transitions are not supported — input timestamps that don't satisfy (timestamp - start) % step == 0 are rejected with an IllegalArgumentException. This matches PROMQL query_range semantics; for calendar-aware bucketing, use a different operator wired to Rounding.Prepared.