view_definition
view_definition ¶
Typed classes for Domo dataset view definitions.
Models the /api/query/v1/datasources/{id}/schema/indexed API response
as structured dataclasses with from_dict classmethods, replacing raw
dict access with typed properties and methods.
Structure
ViewDefinition
├── columns: list[ViewColumn] # view's output columns
├── from_item: ViewFromItem # base dataset + alias
├── joins: list[ViewJoin] # joined datasets
├── select_string: str # SQL SELECT statement
├── column_mapping: dict[str, ViewColumnMapping] # view col → source
│ └── ViewColumnMapping
│ ├── formatted_expression: str # e.g., "base.Name"
│ ├── source_dataset_id: str # resolved from alias
│ └── source_column: str # resolved column name
├── where_columns: dict[str, ViewColumnMapping]
├── having_columns: dict[str, ViewColumnMapping]
├── calculated_columns: dict[str, ViewColumnMapping]
└── remapped_columns: dict[str, ViewColumnMapping]
ViewColumn (from tables[0].columns) ├── name, id, type ├── visible, aggregated, order └── reference_data_source_id
ViewFromItem ├── dataset_id: str └── alias: str (e.g., "base")
ViewJoin ├── dataset_id: str ├── join_type: str (e.g., "left") ├── left_column: str └── right_column: str
ViewColumn
dataclass
¶
ViewColumn(
name: str = "",
id: str = "",
type: str | None = None,
visible: bool = True,
aggregated: bool = False,
order: int = 0,
reference_data_source_id: str | None = None,
)
A column in the view's output schema (from tables[0].columns).
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 |
aggregated |
bool
|
Whether the column is aggregated |
order |
int
|
Column order in the view |
reference_data_source_id |
str | None
|
The view's own dataset ID |
ViewColumnMapping
dataclass
¶
ViewColumnMapping(
formatted_expression: str = "",
data_type: str | None = None,
aggregated: bool = False,
source_dataset_id: str | None = None,
source_column: str | None = None,
)
Maps a view column to its source dataset and column.
Parsed from viewTemplate.fromItemInfo.mapping.columnInfo.
Attributes:
| Name | Type | Description |
|---|---|---|
formatted_expression |
str
|
Raw expression (e.g., |
data_type |
str | None
|
Data type of the column (e.g., "STRING", "DOUBLE") |
aggregated |
bool
|
Whether the column is aggregated |
source_dataset_id |
str | None
|
Resolved dataset ID (from alias lookup) |
source_column |
str | None
|
Resolved source column name (backtick-stripped) |
from_dict
classmethod
¶
from_dict(
obj: dict[str, Any],
alias_to_dataset_id: dict[str, str] | None = None,
) -> ViewColumnMapping
Build a ViewColumnMapping from a columnInfo entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
dict[str, Any]
|
The columnInfo dict for one column (e.g., {"formattedExpression": " |
required |
alias_to_dataset_id
|
dict[str, str] | None
|
Mapping of alias → dataset ID (e.g., {"base": "8e9a51c3-..."}) |
None
|
Source code in src/crew_dcs/classes/DomoDataset/view_definition.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 | |
ViewDefinition
dataclass
¶
ViewDefinition(
name: str = "",
data_source_id: str = "",
version_id: str = "",
columns: list[ViewColumn] = list(),
from_item: ViewFromItem = ViewFromItem(),
joins: list[ViewJoin] = list(),
select_string: str = "",
column_mapping: dict[str, ViewColumnMapping] = dict(),
where_columns: dict[str, ViewColumnMapping] = dict(),
having_columns: dict[str, ViewColumnMapping] = dict(),
calculated_columns: dict[
str, ViewColumnMapping
] = dict(),
remapped_columns: dict[str, ViewColumnMapping] = dict(),
)
Typed representation of a dataset view's definition.
Provides structured access to the view's columns, source datasets, and column mappings with convenience properties for lineage queries.
Usage
vd = ViewDefinition.from_dict(api_response) vd.used_columns_by_dataset # dict[str, set[str]] vd.used_columns # set[str] vd.source_dataset_ids # set[str] vd.column_mapping['Name'] # ViewColumnMapping
available_columns
property
¶
available_columns: list[str]
All available column names in the view's output schema.
column_relationships
property
¶
column_relationships: set[ColumnRelationship]
Set of ColumnRelationship edges for this view.
Direction: from = this view (downstream consumer), to = source dataset (upstream).
Produces: - DIRECT/IDENTITY for each column_mapping entry (SELECT passthrough) - DIRECT/TRANSFORMATION for calculated columns (beast modes) - INDIRECT/FILTER for where_columns - INDIRECT/CONDITIONAL for having_columns - INDIRECT/JOIN for join ON columns
source_dataset_ids
property
¶
source_dataset_ids: set[str]
Set of all source dataset IDs this view depends on.
used_columns
property
¶
used_columns: set[str]
Flat set of all source column names used across all datasets.
used_columns_by_dataset
property
¶
used_columns_by_dataset: dict[str, set[str]]
Map of dataset_id -> set of source column names used from that dataset.
This is the primary lineage property: it tells you which columns from which source datasets the view depends on.
Includes: - All columns from column_mapping (SELECT) - All columns from where_columns (WHERE) - All columns from having_columns (HAVING) - All columns from calculated_columns (beast modes) - Join ON columns (from both sides)
from_dict
classmethod
¶
from_dict(obj: dict[str, Any]) -> ViewDefinition
Build a ViewDefinition from the schema/indexed API response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
dict[str, Any]
|
Full API response dict from /api/query/v1/datasources/{id}/schema/indexed |
required |
Source code in src/crew_dcs/classes/DomoDataset/view_definition.py
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 | |
ViewFromItem
dataclass
¶
ViewFromItem(
dataset_id: str = "", alias: str | None = None
)
The base dataset in a view's FROM clause.
Attributes:
| Name | Type | Description |
|---|---|---|
dataset_id |
str
|
The dataset ID (backtick-stripped) |
alias |
str | None
|
The alias used in SQL (e.g., "base") |
ViewJoin
dataclass
¶
ViewJoin(
dataset_id: str = "",
join_type: str | None = None,
left_column: str | None = None,
right_column: str | None = None,
)
A JOIN in the view's query.
Attributes:
| Name | Type | Description |
|---|---|---|
dataset_id |
str
|
The joined dataset ID (backtick-stripped) |
join_type |
str | None
|
Join type (e.g., "left", "inner") |
left_column |
str | None
|
Column name from the left/base side of the ON expression |
right_column |
str | None
|
Column name from the right/joined side of the ON expression |
build_view_put_schema ¶
build_view_put_schema(
get_response: dict[str, Any],
table_aliases: dict[str, str],
last_modified: str = "",
) -> dict[str, Any]
Normalize a schema/indexed GET response into a PUT-ready schema.
The read endpoint is internally inconsistent for re-PUT; this reconciles it:
- Strip backticks from
selectItemscolumn names (aggregated columns come back backticked, buttablesuses plain names -> "column names do not match"). - Reorder
tablescolumns to match theselectItemsorder. - Add
typeto each join (leftflag ->"left"/"inner"). - Annotate each selectItem
expressionwithtype: {dataType}from the column mapping. - Ensure
fromItemInfo.mappingcarries the emptywhere/having/calculated/remappedblocks the PUT expects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_response
|
dict[str, Any]
|
A |
required |
table_aliases
|
dict[str, str]
|
Map of source-dataset display name -> dataset id. |
required |
last_modified
|
str
|
Optional |
''
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A |
Source code in src/crew_dcs/classes/DomoDataset/view_definition.py
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 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |