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
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 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 | |
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
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 | |
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
orionbelt.models.semantic.DataObject
¶
Bases: BaseModel
A database table or view with its columns and joins.
Source code in src/orionbelt/models/semantic.py
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 | |
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
orionbelt.models.semantic.Measure
¶
Bases: BaseModel
An aggregation measure with optional expression template.
Source code in src/orionbelt/models/semantic.py
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 | |
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.
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.
Source code in src/orionbelt/models/semantic.py
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 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 | |
Query Models¶
orionbelt.models.query.QueryObject
¶
Bases: BaseModel
A complete YAML analytical query.
Source code in src/orionbelt/models/query.py
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
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.