Rifqi Hafizuddin
Claude Opus 5.5
[NOTICKET] feat(query): PA over several periods from summed hours
307bac0 Download src/query/ir/models.py from DataEyond/Agentic-Service-Data-Eyond-Catalog: direct link, hf CLI and curl.
- Browser
- Download file 3.41 kB
-
https://huggingface.co/spaces/DataEyond/Agentic-Service-Data-Eyond-Catalog/resolve/refs%2Fpr%2F28/src/query/ir/models.py
- Command line
-
hf download hf://spaces/DataEyond/Agentic-Service-Data-Eyond-Catalog@refs/pr/28/src/query/ir/models.py
-
curl -L -o models.py https://huggingface.co/spaces/DataEyond/Agentic-Service-Data-Eyond-Catalog/resolve/refs%2Fpr%2F28/src/query/ir/models.py
3.41 kB
| """JSON IR (intermediate representation) Pydantic models. | |
| See ARCHITECTURE.md §7 for the schema. | |
| Scope: filter, group_by, agg, order_by, limit, plus a single-level `joins` to | |
| related tables in the SAME source (KM-652 T4). having, offset, and boolean tree | |
| filters are still deferred. Joins are supported on database (schema) sources only; | |
| the validator rejects them on tabular sources (cross-file merge is a later step). | |
| With joins, `select` / `group_by` / `filters` / `order_by` may reference a | |
| `column_id` from the base table OR any joined table (column_ids are globally | |
| unique), so a measure in one table can be grouped by a dimension in a related one. | |
| """ | |
| from typing import Any, Literal | |
| from pydantic import BaseModel, Field | |
| FilterOp = Literal[ | |
| "=", "!=", "<", "<=", ">", ">=", | |
| "in", "not_in", "is_null", "is_not_null", | |
| "like", "between", | |
| ] | |
| AggFn = Literal["count", "count_distinct", "sum", "avg", "min", "max"] | |
| ValueType = Literal["int", "decimal", "string", "datetime", "date", "bool"] | |
| SortDir = Literal["asc", "desc"] | |
| JoinType = Literal["inner", "left"] | |
| class Join(BaseModel): | |
| """A single equi-join to another table in the same source. | |
| `left_column_id` is a column already in the query (base table or an earlier | |
| join); `right_column_id` is a column in `target_table_id`. The validator | |
| requires the pair to match a foreign key declared in the catalog. | |
| """ | |
| target_table_id: str | |
| left_column_id: str | |
| right_column_id: str | |
| type: JoinType = "inner" | |
| class ColumnSelect(BaseModel): | |
| kind: Literal["column"] = "column" | |
| column_id: str | |
| alias: str | None = None | |
| class ComputedTerm(BaseModel): | |
| column_id: str | |
| sign: Literal["+", "-"] = "+" | |
| class ComputedRatio(BaseModel): | |
| """How an `avg` of a ratio measure is computed from summed inputs (2026-11-09). | |
| `scale * (Σnumerator) / Σdenominator`, each side a signed sum of columns, over | |
| the rows where every term is non-null. Written by code, never by the planner: | |
| the planner's `avg(pa)` is marked with this when the approved domain knowledge | |
| defines the measure from summed hours (docs/plans/RATIO_MEASURES_REQUIREMENTS.md). | |
| `column_id` on the AggSelect stays the measure's own column, so every check | |
| that reads the select still sees `avg(<measure>)`. | |
| """ | |
| numerator: list[ComputedTerm] = Field(min_length=1, max_length=4) | |
| denominator: list[ComputedTerm] = Field(min_length=1, max_length=4) | |
| scale: Literal[1, 100] = 1 | |
| # Method name for the answer's scope line, by language ("id", "en"). | |
| label: dict[str, str] = Field(default_factory=dict) | |
| class AggSelect(BaseModel): | |
| kind: Literal["agg"] = "agg" | |
| fn: AggFn | |
| column_id: str | None = None | |
| alias: str | None = None | |
| computed: ComputedRatio | None = None | |
| SelectItem = ColumnSelect | AggSelect | |
| class FilterClause(BaseModel): | |
| column_id: str | |
| op: FilterOp | |
| value: Any | |
| value_type: ValueType | |
| class OrderByClause(BaseModel): | |
| column_id: str | |
| dir: SortDir = "asc" | |
| class QueryIR(BaseModel): | |
| ir_version: str = "1.0" | |
| source_id: str | |
| table_id: str | |
| joins: list[Join] = Field(default_factory=list) | |
| select: list[SelectItem] | |
| filters: list[FilterClause] = Field(default_factory=list) | |
| group_by: list[str] = Field(default_factory=list) | |
| order_by: list[OrderByClause] = Field(default_factory=list) | |
| limit: int | None = None | |