33import json
44import re
55from pathlib import Path
6- from typing import Any , Optional , Union
6+ from typing import Optional , Union
77
88import attrs
99from gooddata_sdk import CatalogDeclarativeColumn , CatalogDeclarativeTable , CatalogDeclarativeTables
@@ -306,10 +306,11 @@ def is_primary_key(column: DbtModelColumn) -> bool:
306306 return result
307307
308308 def make_grain (self , table : DbtModelTable ) -> list [dict ]:
309- grain = []
310- for column in table .columns .values ():
311- if self .is_primary_key (column ):
312- grain .append ({"id" : column .ldm_id , "type" : "attribute" })
309+ grain = [
310+ {"id" : column .ldm_id , "type" : "attribute" }
311+ for column in table .columns .values ()
312+ if self .is_primary_key (column )
313+ ]
313314 return grain
314315
315316 # TODO - constraints are stored in special nodes
@@ -326,21 +327,22 @@ def make_grain(self, table: DbtModelTable) -> list[dict]:
326327
327328 @staticmethod
328329 def find_role_playing_tables (tables : list [DbtModelTable ]) -> dict :
329- result = {}
330- for table in tables :
331- references : dict [str , Any ] = {}
332- for column in table .columns .values ():
333- if column .is_reference ():
334- referenced_table = column .meta .gooddata .referenced_table
335- if referenced_table is not None :
336- if referenced_table in references :
337- references [referenced_table ].append (column .name )
338- else :
339- references [referenced_table ] = [column .name ]
340- for referenced_object_id , columns in references .items ():
341- if len (columns ) > 1 :
342- result [referenced_object_id ] = columns
343- return result
330+ return {
331+ referenced_object_id : columns
332+ for table in tables
333+ for column in table .columns .values ()
334+ if column .is_reference ()
335+ for referenced_table in [column .meta .gooddata .referenced_table ]
336+ if referenced_table is not None
337+ for referenced_object_id , columns in {
338+ referenced_table : [
339+ col .name
340+ for col in table .columns .values ()
341+ if col .is_reference () and col .meta .gooddata .referenced_table == referenced_table
342+ ]
343+ }.items ()
344+ if len (columns ) > 1
345+ }
344346
345347 def make_references (self , table : DbtModelTable , role_playing_tables : dict ) -> list [dict ]:
346348 references = []
@@ -369,20 +371,19 @@ def make_references(self, table: DbtModelTable, role_playing_tables: dict) -> li
369371
370372 @staticmethod
371373 def make_facts (table : DbtModelTable ) -> list [dict ]:
372- facts = []
373- for column in table .columns .values ():
374- if column .gooddata_is_fact ():
375- facts .append (
376- {
377- "id" : column .ldm_id ,
378- # TODO - all titles filled from dbt descriptions, incorrect! No title in dbt models.
379- "title" : column .gooddata_ldm_title ,
380- "description" : column .gooddata_ldm_description ,
381- "source_column" : column .name ,
382- "source_column_data_type" : column .data_type ,
383- "tags" : [table .gooddata_ldm_title ] + column .tags ,
384- }
385- )
374+ facts = [
375+ {
376+ "id" : column .ldm_id ,
377+ # TODO - all titles filled from dbt descriptions, incorrect! No title in dbt models.
378+ "title" : column .gooddata_ldm_title ,
379+ "description" : column .gooddata_ldm_description ,
380+ "source_column" : column .name ,
381+ "source_column_data_type" : column .data_type ,
382+ "tags" : [table .gooddata_ldm_title ] + column .tags ,
383+ }
384+ for column in table .columns .values ()
385+ if column .gooddata_is_fact ()
386+ ]
386387 return facts
387388
388389 @staticmethod
0 commit comments