33import json
44import re
55from pathlib import Path
6- from typing import Optional , Union
6+ from typing import Union
77
88import attrs
99from gooddata_sdk import CatalogDeclarativeColumn , CatalogDeclarativeTable , CatalogDeclarativeTables
2727
2828@attrs .define (auto_attribs = True , kw_only = True )
2929class DbtModelMetaGoodDataTableProps (Base ):
30- model_id : Optional [ str ] = None
30+ model_id : str | None = None
3131
3232
3333@attrs .define (auto_attribs = True , kw_only = True )
3434class DbtModelMetaGoodDataColumnProps (Base ):
35- id : Optional [str ] = None
36- ldm_type : Optional [GoodDataLdmType ] = None
37- referenced_table : Optional [str ] = None
38- label_type : Optional [GoodDataLabelType ] = None
39- attribute_column : Optional [str ] = None
40- sort_column : Optional [str ] = None
41- sort_direction : Optional [GoodDataSortDirection ] = None
42- default_view : Optional [bool ] = None
35+ id : str | None = None
36+ ldm_type : GoodDataLdmType | None = None
37+ referenced_table : str | None = None
38+ label_type : GoodDataLabelType | None = None
39+ attribute_column : str | None = None
40+ sort_column : str | None = None
41+ sort_direction : GoodDataSortDirection | None = None
42+ default_view : bool | None = None
43+ geo_area_config : dict [str , dict [str , str ]] | None = None
4344
4445 @property
45- def gooddata_ref_table_ldm_id (self ) -> Optional [ str ] :
46+ def gooddata_ref_table_ldm_id (self ) -> str | None :
4647 if self .referenced_table :
4748 return self .referenced_table .lower ()
4849 return None
@@ -73,7 +74,7 @@ class DbtModelBase(Base):
7374 tags : list [str ]
7475 # If 2+ references point to the same table, the table plays multiple roles,
7576 # it must be generated as multiple datasets
76- role_name : Optional [ str ] = None
77+ role_name : str | None = None
7778
7879 # TODO - duplicate of backend logic.
7980 # Solution: use result of generateLdm as a master template, and override based on dbt metadata only if necessary
@@ -120,7 +121,7 @@ def upper_case_name(self) -> None:
120121
121122@attrs .define (auto_attribs = True , kw_only = True )
122123class DbtModelColumn (DbtModelBase ):
123- data_type : Optional [ str ]
124+ data_type : str | None
124125 meta : DbtModelMetaGoodDataColumn = attrs .field (factory = DbtModelMetaGoodDataColumn )
125126
126127 # Enable to override LDM ID for LDM entities derived from columns (attributes, ...)
@@ -130,21 +131,21 @@ def ldm_id(self) -> str:
130131 return self .meta .gooddata .id or self .gooddata_ldm_id
131132
132133 @property
133- def ldm_type (self ) -> Optional [ str ] :
134+ def ldm_type (self ) -> str | None :
134135 if self .meta .gooddata .ldm_type is None :
135136 return None
136137 else :
137138 return self .meta .gooddata .ldm_type .value
138139
139140 @property
140- def label_type (self ) -> Optional [ str ] :
141+ def label_type (self ) -> str | None :
141142 if self .meta .gooddata .label_type is None :
142143 return None
143144 else :
144145 return self .meta .gooddata .label_type .value
145146
146147 @property
147- def sort_direction (self ) -> Optional [ str ] :
148+ def sort_direction (self ) -> str | None :
148149 if self .meta .gooddata .sort_direction is None :
149150 return None
150151 else :
@@ -387,22 +388,23 @@ def make_facts(table: DbtModelTable) -> list[dict]:
387388 return facts
388389
389390 @staticmethod
390- def make_labels (table : DbtModelTable , attribute_column : DbtModelColumn ) -> tuple [list [dict ], Optional [ dict ] ]:
391+ def make_labels (table : DbtModelTable , attribute_column : DbtModelColumn ) -> tuple [list [dict ], dict | None ]:
391392 labels = []
392393 default_view = None
393394 for column in table .columns .values ():
394395 if column .gooddata_is_label (attribute_column .name ):
395- labels .append (
396- {
397- "id" : column .ldm_id ,
398- "title" : column .gooddata_ldm_title ,
399- "description" : column .gooddata_ldm_description ,
400- "source_column" : column .name ,
401- "source_column_data_type" : column .data_type ,
402- "value_type" : column .label_type ,
403- "tags" : [table .gooddata_ldm_title ] + column .tags ,
404- }
405- )
396+ label_dict : dict = {
397+ "id" : column .ldm_id ,
398+ "title" : column .gooddata_ldm_title ,
399+ "description" : column .gooddata_ldm_description ,
400+ "source_column" : column .name ,
401+ "source_column_data_type" : column .data_type ,
402+ "value_type" : column .label_type ,
403+ "tags" : [table .gooddata_ldm_title ] + column .tags ,
404+ }
405+ if column .meta .gooddata .geo_area_config is not None :
406+ label_dict ["geo_area_config" ] = column .meta .gooddata .geo_area_config
407+ labels .append (label_dict )
406408 if column .meta .gooddata .default_view :
407409 default_view = {
408410 "id" : column .ldm_id ,
@@ -507,7 +509,7 @@ def populate_role_playing_tables(tables: list[DbtModelTable], role_playing_table
507509 result .append (table )
508510 return result
509511
510- def make_declarative_datasets (self , data_source_id : str , model_ids : Optional [ list [str ]] ) -> dict :
512+ def make_declarative_datasets (self , data_source_id : str , model_ids : list [str ] | None ) -> dict :
511513 result : dict [str , list ] = {"datasets" : [], "date_instances" : []}
512514 model_tables = [t for t in self .tables if not model_ids or t .meta .gooddata .model_id in model_ids ]
513515 role_playing_tables = self .find_role_playing_tables (model_tables )
@@ -517,7 +519,7 @@ def make_declarative_datasets(self, data_source_id: str, model_ids: Optional[lis
517519 result = self .make_dataset (data_source_id , table , role_playing_tables , result )
518520 return result
519521
520- def get_entity_type (self , table_name : str , column_name : str ) -> Optional [ str ] :
522+ def get_entity_type (self , table_name : str , column_name : str ) -> str | None :
521523 comp_table_name = table_name
522524 if self .upper_case :
523525 comp_table_name = table_name .upper ()
0 commit comments