Model and Query Objects¶
The objects you build, pass around, and get back: the model itself, the query against it, and the errors when something does not line up.
Semantic Model¶
orionbelt.models.semantic.SemanticModel
¶
Bases: BaseModel
Complete semantic model parsed from OBML YAML.
Source code in src/orionbelt/models/semantic.py
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 | |
effective_measures
property
¶
Declared measures plus synthesized row-count measures (declared win).
The single source of truth for the model's queryable measure namespace.
Synthesized counts are not persisted on measures (they never
roundtrip through YAML/OSI) — they are computed on demand here so every
read/resolve surface sees them as ordinary named measures.
effective_joins(object_name, path_overrides=None)
¶
The joins of object_name that are active under path_overrides.
One named secondary path per (source, target) pair replaces that
pair's primary join; every other pair keeps its primary. This is the
rule :class:~orionbelt.compiler.graph.JoinGraph traverses by, and
anything deriving join columns has to use the same one. Filtering
secondary joins out unconditionally instead read a conformed subquery's
key off the primary join even when the query had asked for the secondary
path, which silently answered at the wrong grain.
Takes a plain mapping rather than the query's usePathNames because
models.query imports this module, not the other way round.
Source code in src/orionbelt/models/semantic.py
column_reference_objects(object_name, column_label)
¶
Other data objects a column's expression reads.
A computed column names a sibling with {Column} and a column of
another data object with the qualified {[Data Object].[Column]}
form. Reading the latter means joining that object in, so callers add
what this returns to a query's join requirements — it is deliberately
not part of measure_source_objects, which drives multi-fact
detection: a cross-object computed column is one row of a star, not a
second fact.
Follows nested computed columns, across objects as well as within one, and returns every object involved except the owning one — which stays out however many hops away the walk reaches it again, because it is joined already by virtue of owning the column.
Empty for a plain column and for a computed one that reads only siblings, which is what makes this cheap to call on every column.
Source code in src/orionbelt/models/semantic.py
measure_join_objects(name)
¶
Objects a measure needs joined without sourcing values from them.
Two kinds. A withinGroup column becomes the aggregate's ORDER BY,
so it has to resolve while contributing no value. And any column the
measure touches — its own, its filters', its filter context's — may be
computed from another data object, which the expression names directly
and so has to be joined.
Deliberately separate from the objects a measure sources: that set drives multi-fact detection, and neither an ordering column nor an expression's neighbour is a second fact.
Lives on the model because two callers need the same answer — the planner, which adds these to a query's join requirements, and composability, which must not advertise a measure the planner will then refuse. Computed independently, they drifted.
Source code in src/orionbelt/models/semantic.py
2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 | |
dimension_join_objects(name)
¶
Objects a dimension needs joined besides the one it belongs to.
Its column may be computed from another data object's column, which is inlined wherever the dimension is projected or filtered.
Source code in src/orionbelt/models/semantic.py
common_join_targets(objects, path_overrides=None)
¶
Every data object all of objects join to directly, in name order.
The candidates for conforming independent facts to a shared grain. More than one is an ambiguity rather than a tie to break: two facts sharing both a calendar and a store conform to different numbers depending which is used, so callers refuse rather than pick.
Which joins count depends on the query's active usePathNames: see
:meth:effective_joins.
Source code in src/orionbelt/models/semantic.py
unnest_root(name)
¶
The nearest ancestor of name that a FROM clause can actually name.
A nestedIn object's rows are an array column on its parent, so they
exist only inside the parent's row: it can never be a query's base
object nor a CFL leg's root, and it is never what a plan selects from.
Walking up gives the object that can be, and it always covers what the
nested one does, since the parent reaches the child and not the reverse.
Returns name unchanged for an ordinary object, and stops on a chain that loops - the semantic validator refuses one, but this is reached from the compiler, which must terminate on any model it is handed.
Source code in src/orionbelt/models/semantic.py
reaggregated_measure(name)
¶
The measure a reaggregate metric's first stage reads, with its name.
Follows measure through nested reaggregate metrics, and a cumulative
metric a first stage reads, down to the measure at the bottom: that is
the fact every stage reads and the source of the values each one
aggregates again. None when the chain ends anywhere else.
Source code in src/orionbelt/models/semantic.py
orionbelt.models.semantic.DataObject
¶
Bases: BaseModel
A database table or view with its columns and joins.
Source code in src/orionbelt/models/semantic.py
906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
is_nested
property
¶
Whether this object's rows come from unnesting a parent's column.
qualified_code
property
¶
Full qualified table reference: database.schema.code.
require_table_source()
¶
Raise unless this object has a table a FROM clause can name.
A nestedIn object without code has no table: its rows are an
array column on its parent, reached by an unnest that names the parent
rather than by selecting from anything. The planner puts it in the FROM
clause that way and never asks for a table, so reaching here means
something tried to select from it - which is what this refuses, rather
than falling through to an empty code and emitting
FROM "" AS "Charge Labels".
Source code in src/orionbelt/models/semantic.py
orionbelt.models.semantic.Dimension
¶
Bases: BaseModel
A named dimension referencing a data object column.
Source code in src/orionbelt/models/semantic.py
path_name = Field(None, alias='pathName')
class-attribute
instance-attribute
¶
The pathName of the join from via to dataObject this dimension reads through.
Pins the dimension to one role of a data object that via joins more
than once, such as the sales and the support employee of an order. Each
role compiles to its own aliased join of the table, so several roles can
appear in one query, which the query-level usePathNames cannot do: it
swaps the pair's join for every dimension at once.
The join must be declared on via and target dataObject directly;
it may be the primary join or a secondary one.
value_search = Field(True, alias='valueSearch')
class-attribute
instance-attribute
¶
Whether the value search (/values) may list this dimension's values.
A query may still filter on it; false only keeps its values from being
enumerated, for a column such as an email address or a national ID.
orionbelt.models.semantic.Measure
¶
Bases: BaseModel
An aggregation measure with optional expression template.
Source code in src/orionbelt/models/semantic.py
1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 | |
default_value = Field(None, alias='defaultValue')
class-attribute
instance-attribute
¶
Value to report when the aggregate has nothing to add up.
An aggregate over no rows is NULL in standard SQL, and a filtered measure reaches that state routinely — the group exists, the filter matches none of it. Whether the answer should read as NULL or as zero is the modeller's call, not the engine's, and engines disagree: ClickHouse returns 0 where Postgres, DuckDB and the rest return NULL for an aggregate over an empty row set. Setting this pins the value on every dialect; leaving it unset keeps the SQL-standard NULL.
Same slot as :attr:Metric.default_value, which does the same job for a
window function with nothing to look at.
anchor = None
class-attribute
instance-attribute
¶
Data object whose grain this measure's expression is evaluated at.
Only meaningful for an expression reading columns from independent facts
— objects no single join path reaches together. Without it such a measure
has no defined value: UNION ALL stacks the facts rather than joining
them, so no row carries both columns. Naming an anchor says which fact's
rows the expression runs over; the other facts are aggregated to the key
they share with it and joined on many-to-one, so nothing fans out.
It cannot be inferred. {[Returns].[Qty]} / {[Sales].[Qty]} is symmetric,
and anchoring it on Returns rather than the shared calendar key changes
AVG from 0.5 to 0.3333 (different row populations), so a wrong guess is
a wrong number rather than an error.
A bare data-object name, like :attr:Dimension.via.
percentile = None
class-attribute
instance-attribute
¶
The fraction of percentile_cont / percentile_disc, between 0 and
1 (0.9 for the 90th percentile).
source_objects
property
¶
Data objects whose columns this measure reads.
Covers both declaration forms: the structured columns: list and
{[Object].[Column]} references inside expression:.
referenced_objects
property
¶
:attr:source_objects, in the order the declaration mentions them.
Ordered for determinism, not for meaning. An earlier design used the
first entry as the default :attr:anchor and was removed: it made a
commutative rewrite change the answer, since
{[Sales].[Qty]} * {[Returns].[Qty]} and the operands swapped would
anchor on different facts and return different averages. Nothing reads
position now, and nothing should.
orionbelt.models.semantic.Metric
¶
Bases: BaseModel
A metric: derived expression, cumulative window, or period-over-period comparison.
Derived (default): references measures by name using {[Measure Name]} syntax.
Cumulative: applies a window function to an existing measure, ordered by a time
dimension. Supports running totals, rolling windows, and grain-to-date resets.
Period-over-Period: compares a measure's value against a prior time period using
a synthetical date spine. Supports ratio, difference, previous value, and percent change.
Reaggregate: aggregates a measure at the query grain plus the per dimensions,
then aggregates those values again to the query grain (e.g. average revenue per
customer, by country).
Source code in src/orionbelt/models/semantic.py
1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 | |
window_span = Field(None, alias='windowSpan')
class-attribute
instance-attribute
¶
A rolling window over a span of time ({count: 90, unit: day}) rather
than window periods: the measure over its rows in the span ending at
each period's end. Cumulative metrics only.
frame = None
class-attribute
instance-attribute
¶
The rows a sum / avg / min / max / count window
metric aggregates over. Window metrics only.
Query Models¶
orionbelt.models.query.QueryObject
¶
Bases: BaseModel
A complete YAML analytical query.
Source code in src/orionbelt/models/query.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 | |
allow_fan_out = Field(False, alias='allowFanOut')
class-attribute
instance-attribute
¶
Silence fan-out warnings for this query.
The query-level counterpart of Measure.allowFanOut. A measure reading
both a base-grain column and one from an object the joins replicate is
evaluated per base row: right for an extended price
(quantity * list price), wrong for anything that reads the replicated
row's own magnitude. Nothing in the declarations separates the two, so the
compiler warns rather than refusing, and this says the duplication is
understood and intended for this query.
orionbelt.models.query.QuerySelect
¶
Bases: BaseModel
The SELECT part of a query.
Two mutually exclusive modes:
- Aggregate mode (default):
dimensions+measuresproduce a grouped, aggregated result (GROUP BY dimensions, aggregate measures). - Raw mode:
fieldsreturns un-aggregated rows from one or more data objects joined per the model. Setdistinct: trueforSELECT DISTINCT. Raw mode rejectsdimensions,measures,metrics, andHAVING.
Source code in src/orionbelt/models/query.py
is_raw
property
¶
True when this select is in raw mode (fields-based projection).
orionbelt.models.query.QueryFilter
¶
Bases: BaseModel
A filter condition in a query.
Source code in src/orionbelt/models/query.py
orionbelt.models.query.UsePathName
¶
Bases: BaseModel
Selects a named secondary join path for a specific (source, target) pair.
Source code in src/orionbelt/models/query.py
orionbelt.models.query.DimensionRef
¶
Bases: BaseModel
Reference to a dimension, optionally with time grain.
Supports notation like "customer.country" or "order.order_date:month".
Source code in src/orionbelt/models/query.py
parse(raw)
classmethod
¶
Parse 'name:grain' notation.
Error Models¶
orionbelt.models.errors.SemanticError
¶
Bases: BaseModel
A structured error or warning with optional source position and remediation.
Used uniformly for errors (severity="error") and warnings (severity="warning").
See models/warnings.py for the stable warning code taxonomy.
Source code in src/orionbelt/models/errors.py
as_text(*, with_path=False)
¶
One line for text-only surfaces (CLI, pgwire): code, message and remedy.
Source code in src/orionbelt/models/errors.py
orionbelt.models.errors.ValidationResult
¶
Bases: BaseModel
Result of semantic model validation.
Source code in src/orionbelt/models/errors.py
orionbelt.models.errors.SourceSpan
¶
Bases: BaseModel
Points to exact location in YAML source for error reporting.