data_model_definition
data_model_definition ¶
Typed classes for Domo data-model (semantic model) definitions.
Models the /api/query/v1/datasources/{id}/schema/indexed API response for a
data-model datasource as structured dataclasses with from_dict
classmethods.
A data model's definition lives under the response model key (NOT
viewTemplate — that is a dataset-view concept). Its two foundational
pieces are:
model.objects -> the tables (source datasets) participating
model.relationships -> the JOIN criteria between those tables
Column detail comes from tables[0].modeledColumns.
Structure
DataModelTemplate ├── objects: dict[str, DataModelObject] # table alias -> source dataset │ └── DataModelObject │ ├── name, object_type, datasource_id │ ├── include, exclude │ └── columns: list[DataModelColumn] ├── relationships: list[DataModelRelationship] # the JOINs │ └── DataModelRelationship │ ├── left, right # object names │ ├── cardinality, join_type, primary │ ├── left_keys, right_keys # column names (backtick-stripped) └── convenience: source_dataset_ids, tables, datasource_id_by_object
This is intentionally separate from ViewDefinition (dataset-view's
viewTemplate): a data model and a dataset view are foundationally
different definition formats, so they get independent parsers.
DataModelColumn
dataclass
¶
DataModelColumn(
name: str = "",
id: str = "",
type: str | None = None,
visible: bool = True,
order: int = 0,
reference_data_source_id: str | None = None,
)
A column exposed by a data-model object (from tables[0].modeledColumns).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Column display name |
id |
str
|
Column ID (usually same as name) |
type |
str | None
|
Data type (e.g., "STRING", "DOUBLE", "DATE") |
visible |
bool
|
Whether the column is visible in the model output |
order |
int
|
Column order |
reference_data_source_id |
str | None
|
The source dataset the column comes from |
DataModelObject
dataclass
¶
DataModelObject(
name: str = "",
object_type: str | None = None,
datasource_id: str = "",
include: list[str] = list(),
exclude: list[str] = list(),
columns: list[DataModelColumn] = list(),
cloud_id: str = "domo",
is_new: bool = False,
)
A table participating in a data model (from model.objects).
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
The object's name/alias within the model (the objects key) |
object_type |
str | None
|
The object type (e.g., "DATASET") |
datasource_id |
str
|
The underlying source dataset ID |
include |
list[str]
|
Explicitly included column names (empty = all) |
exclude |
list[str]
|
Explicitly excluded column names |
columns |
list[DataModelColumn]
|
Modeled columns contributed by this object |
to_schema ¶
to_schema() -> dict[str, Any]
Serialize to the objects entry shape expected by the model PUT.
Source code in src/crew_dcs/classes/DomoDataset/data_model_definition.py
137 138 139 140 141 142 143 144 145 146 | |
DataModelRelationship
dataclass
¶
DataModelRelationship(
left: str = "",
right: str = "",
cardinality: str | None = None,
join_type: str | None = None,
primary: bool = False,
left_keys: list[str] = list(),
right_keys: list[str] = list(),
alias: str | None = None,
)
A relationship (JOIN) between two objects in a data model.
Attributes:
| Name | Type | Description |
|---|---|---|
left |
str
|
Name of the left object (the "one" side for one_to_many) |
right |
str
|
Name of the right object (the "many" side for one_to_many) |
cardinality |
str | None
|
Relationship cardinality (e.g., "one_to_many") |
join_type |
str | None
|
SQL join type (e.g., "INNER", "LEFT") |
primary |
bool
|
Whether this is the model's primary relationship |
left_keys |
list[str]
|
Left-side join column names (backtick-stripped) |
right_keys |
list[str]
|
Right-side join column names (backtick-stripped) |
alias |
str | None
|
Optional alias for the relationship. The Domo API requires a
non-null alias for non-primary relationships, but the validation
is buggy — it rejects all string values. The workaround is to
set |
to_schema ¶
to_schema() -> dict[str, Any]
Serialize to the relationships entry shape expected by the PUT.
Column names are emitted un-backticked (the PUT format), matching how
from_dict strips them on read.
Note: The Domo API has a validation bug where non-primary relationships
require a non-null alias field, but rejects all string values for it.
The workaround is to set primary=True for all relationships. This
method preserves the alias value for round-trip fidelity.
Source code in src/crew_dcs/classes/DomoDataset/data_model_definition.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
DataModelTemplate
dataclass
¶
DataModelTemplate(
name: str = "",
data_source_id: str = "",
version_id: str = "",
objects: dict[str, DataModelObject] = dict(),
relationships: list[DataModelRelationship] = list(),
)
Typed representation of a Domo data model's definition.
Provides structured access to the model's tables (objects) and the JOIN criteria (relationships) between them.
Usage
dm = DataModelTemplate.from_dict(api_response) dm.tables # list[DataModelObject] dm.relationships # list[DataModelRelationship] dm.source_dataset_ids # set[str] dm.datasource_id_by_object # dict[object_name -> dataset_id]
datasource_id_by_object
property
¶
datasource_id_by_object: dict[str, str]
Map of object name -> underlying source dataset ID.
primary_relationship
property
¶
primary_relationship: DataModelRelationship | None
The model's primary relationship, if one is flagged.
source_dataset_ids
property
¶
source_dataset_ids: set[str]
Set of underlying source dataset IDs this model depends on.
to_schema ¶
to_schema() -> dict[str, Any]
Serialize back to the schema payload for the model PUT.
Produces {"objects": {...}, "relationships": [...]} — the shape the
PUT /api/query/v1/semantic-models/{id} endpoint expects. This is a
lossless round-trip of the tables + JOIN criteria (the model's editable
definition).
Source code in src/crew_dcs/classes/DomoDataset/data_model_definition.py
289 290 291 292 293 294 295 296 297 298 299 300 | |
used_columns_by_dataset ¶
used_columns_by_dataset() -> dict[str, set[str]]
Map of source dataset ID -> set of column names exposed by the model.
Includes modeled columns and relationship join keys.
Source code in src/crew_dcs/classes/DomoDataset/data_model_definition.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |