---
name: Stage
lang: cpp
domain: core
version: "1.0.0"
algebraic: product
definition: |
  struct Stage {
      std::vector<Filter>          filters;
      std::vector<DerivedColumn>   derived;
      std::vector<std::string>     breakouts;
      std::vector<Aggregation>     aggregations;
      std::vector<SortClause>      sorts;
  };
description: "Layer del pipeline TQL. Stage 0 = Raw (filters + derived + sort). Stage 1+ pueden agrupar (breakouts + aggregations + sort). Consumida por compute_stage."
tags: [tql, stage, pipeline, product-type, mbql]
uses_types: [Filter_cpp_core, Op_cpp_core]
file_path: "cpp/functions/core/data_table_types.h"
---

## Notas

Inspirado en MBQL `:filter` / `:breakout` / `:aggregation` / `:order-by`. Diferencia clave: TQL chain N stages explicitos, cada uno consume el output del anterior. MBQL usa `:source-query` recursivo.

Breakout strings pueden llevar sufijo `:granularity` para cols Date (fase 10): `"ts:month"`, `"ts:week"`, etc. Ver `parse_breakout_granularity()`.

## Usado por

- `State_cpp_core` (lista de stages)
- `compute_stage_cpp_core` (executes a single Stage)
- `compute_pipeline_cpp_core` (chains stages 0..N)
- `tql_emit_cpp_core` / `tql_apply_cpp_core` (round-trip Lua)
- `tql_to_sql_cpp_core` → CTE chain DuckDB
