recon_gen.common.tree.fields

Field-well leaf nodes — Dim + Measure typed wrappers.

Every visual’s field wells contain a mix of DimensionField and MeasureField entries (source / target columns, group-by fields, aggregated values). These tree nodes wrap them with typed factories (Dim.date(...), Measure.sum(...)) so construction-time typing drives what the visual gets, rather than hand-wiring the underlying models every time.

Auto field_id (L.1.16): both Dim and Measure accept an optional field_id keyword. When omitted, the App walker assigns f-{visual_kind}-s{sheet_idx}-v{visual_idx}-{role}{slot_idx} at emit time. Authors typically pass Dim(ds, "column_name") and reference the leaf via Python variable for sort / drill plumbing (both accept Dim / Measure object refs in addition to bare field-id strings).

Functions

resolve_field_id(ref)

Read the resolved field_id off a Dim / Measure / bare string.

row_one_calc_name(dataset)

Convention name for the literal-1 CalcField backing Measure.kind == "count" row-count semantics on dataset.

Classes

Dim(dataset, column[, kind, ...])

One dimension field-well entry — typed wrapper that emits a DimensionField of the appropriate kind.

Measure(dataset, column, kind, *[, ...])

One value field-well entry — typed wrapper that emits a MeasureField with the appropriate aggregation shape.

class recon_gen.common.tree.fields.Dim(dataset, column, kind='categorical', *, date_granularity=None, field_id=AUTO, currency=False)[source]

Bases: object

One dimension field-well entry — typed wrapper that emits a DimensionField of the appropriate kind.

dataset is a Dataset object ref — the locked L.1.7 hard switch. The dataset must be registered on the parent App (via app.add_dataset()) for the analysis to emit.

column accepts either a bare str (a real column on the dataset) or a CalcField object ref (an analysis-level calculated field). The CalcField ref carries the calc-field identity through the type checker — the App’s emit-time validation catches references to unregistered calc fields.

Default kind is categorical (the most common); use the date() / numerical() classmethods for the other variants.

field_id is keyword-only and Optional (L.1.16 auto-ID). When omitted, the App walker assigns one based on the leaf’s tree position. Pass an explicit field_id="..." only when external consumers (browser e2e selectors, etc.) need a stable id — cross-reference plumbing (sort_by, drill writes) accepts the leaf object directly.

Identity-keyed (eq=False) so the auto-id resolver can mutate the field_id at emit time. Dim leaves stay hashable via the default object identity hash, which lets the dependency graph set-membership check work.

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • kind (Literal['categorical', 'date', 'numerical'])

  • date_granularity (Literal['YEAR', 'QUARTER', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MILLISECOND'] | None)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

calc_field()[source]

The CalcField this Dim references, or None if it points at a real dataset column. Used by the dependency-graph walk.

Return type:

CalcField | None

column: str | CalcField | Column
currency: bool = False
dataset: Dataset
classmethod date(dataset, column, *, date_granularity='DAY', field_id=AUTO)[source]

Date dimension. date_granularity defaults to "DAY" — QuickSight’s most common bucket for daily series. Pass None to omit the granularity (the renderer falls back to its default, which can shift bucketing on day-vs-month dashboards).

Return type:

Dim

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • date_granularity (Literal['YEAR', 'QUARTER', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MILLISECOND'] | None)

  • field_id (str | Literal[_AutoSentinel.AUTO])

date_granularity: Literal['YEAR', 'QUARTER', 'MONTH', 'WEEK', 'DAY', 'HOUR', 'MINUTE', 'SECOND', 'MILLISECOND'] | None = None
emit()[source]
Return type:

DimensionField

emit_unaggregated_field()[source]

Emit the raw UnaggregatedField dict shape used inside TableUnaggregatedFieldWells.Values. The model layer types that field as list[dict[str, Any]] rather than a typed union, so the tree emits it as a dict directly.

Q.1.a.7 — When currency=True is set on a numerical Dim, the same USD FormatConfiguration that emit() wires onto a NumericalDimensionField is also folded into the unaggregated field shape so table cells render with “$” + thousands separator + 2 decimals. Without this, currency=True only took effect when the Dim was used as a chart axis or KPI value, not when it was used as a table column (the by-far common case).

Return type:

dict[str, object]

field_id: str | Literal[_AutoSentinel.AUTO] = 'auto'
kind: Literal['categorical', 'date', 'numerical'] = 'categorical'
classmethod numerical(dataset, column, *, field_id=AUTO, currency=False)[source]
Return type:

Dim

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

class recon_gen.common.tree.fields.Measure(dataset, column, kind, *, field_id=AUTO, currency=False, decimals=None)[source]

Bases: object

One value field-well entry — typed wrapper that emits a MeasureField with the appropriate aggregation shape.

dataset is a Dataset object ref (L.1.7 hard switch). The dataset must be registered on the parent App for the analysis to emit.

field_id is keyword-only and Optional (L.1.16 auto-ID). When omitted, the App walker assigns one based on the leaf’s tree position.

Use the classmethod factories for ergonomic construction: Measure.sum(...), Measure.distinct_count(...), etc. Aggregation kind determines which underlying model class is emitted (numerical aggregations on numeric columns, categorical on count-style aggregations).

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • kind (Literal['sum', 'max', 'min', 'average', 'count', 'distinct_count'])

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

  • decimals (int | None)

classmethod average(dataset, column, *, field_id=AUTO, currency=False, decimals=None)[source]
Return type:

Measure

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

  • decimals (int | None)

calc_field()[source]

The CalcField this Measure references, or None if it points at a real dataset column.

Return type:

CalcField | None

column: str | CalcField | Column
classmethod count(dataset, column, *, field_id=AUTO)[source]
Return type:

Measure

Parameters:
currency: bool = False
dataset: Dataset
decimals: int | None = None
classmethod distinct_count(dataset, column, *, field_id=AUTO)[source]
Return type:

Measure

Parameters:
emit()[source]
Return type:

MeasureField

field_id: str | Literal[_AutoSentinel.AUTO] = 'auto'
kind: Literal['sum', 'max', 'min', 'average', 'count', 'distinct_count']
classmethod max(dataset, column, *, field_id=AUTO, currency=False, decimals=None)[source]
Return type:

Measure

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

  • decimals (int | None)

classmethod min(dataset, column, *, field_id=AUTO, currency=False, decimals=None)[source]
Return type:

Measure

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

  • decimals (int | None)

classmethod sum(dataset, column, *, field_id=AUTO, currency=False, decimals=None)[source]
Return type:

Measure

Parameters:
  • dataset (Dataset)

  • column (str | CalcField | Column)

  • field_id (str | Literal[_AutoSentinel.AUTO])

  • currency (bool)

  • decimals (int | None)

recon_gen.common.tree.fields.resolve_field_id(ref)[source]

Read the resolved field_id off a Dim / Measure / bare string.

Return type:

str

Parameters:

ref (Dim | Measure | str)

recon_gen.common.tree.fields.row_one_calc_name(dataset)[source]

Convention name for the literal-1 CalcField backing Measure.kind == "count" row-count semantics on dataset.

Returns "_row_one_<sanitized-dataset-id>". Dashes in the dataset identifier are replaced with underscores so the name is QS-safe (QS calc field names accept underscores; dashes are allowed too but underscores stay closer to convention).

Return type:

str

Parameters:

dataset (Dataset)