1
1
import re
2
2
import urllib .parse
3
3
from enum import Enum
4
- from typing import Any , Dict , List , Literal , Optional , Sequence
4
+ from typing import Any , Dict , List , Literal , NamedTuple , Optional , Sequence
5
5
6
6
from dagster import (
7
7
UrlMetadataValue ,
@@ -78,15 +78,22 @@ class PowerBIContentData:
78
78
properties : Dict [str , Any ]
79
79
80
80
81
- @whitelist_for_serdes
82
- @record
83
- class PowerBITranslatorData (PowerBIContentData ):
81
+ class PowerBITranslatorData (NamedTuple ):
84
82
"""A record representing a piece of content in PowerBI and the PowerBI workspace data.
85
83
Includes the content's type and data as returned from the API.
86
84
"""
87
85
86
+ content_data : "PowerBIContentData"
88
87
workspace_data : "PowerBIWorkspaceData"
89
88
89
+ @property
90
+ def content_type (self ) -> PowerBIContentType :
91
+ return self .content_data .content_type
92
+
93
+ @property
94
+ def properties (self ) -> Dict [str , Any ]:
95
+ return self .content_data .properties
96
+
90
97
91
98
@whitelist_for_serdes
92
99
@record
@@ -165,7 +172,7 @@ class DagsterPowerBITranslator:
165
172
Subclass this class to implement custom logic for each type of PowerBI content.
166
173
"""
167
174
168
- def get_asset_spec (self , data : PowerBIContentData ) -> AssetSpec :
175
+ def get_asset_spec (self , data : PowerBITranslatorData ) -> AssetSpec :
169
176
data = check .inst (data , PowerBITranslatorData )
170
177
if data .content_type == PowerBIContentType .DASHBOARD :
171
178
return self .get_dashboard_spec (data )
@@ -182,11 +189,11 @@ def get_asset_spec(self, data: PowerBIContentData) -> AssetSpec:
182
189
breaking_version = "1.10" ,
183
190
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
184
191
)
185
- def get_dashboard_asset_key (self , data : PowerBIContentData ) -> AssetKey :
192
+ def get_dashboard_asset_key (self , data : PowerBITranslatorData ) -> AssetKey :
186
193
data = check .inst (data , PowerBITranslatorData )
187
194
return self .get_dashboard_spec (data ).key
188
195
189
- def get_dashboard_spec (self , data : PowerBIContentData ) -> AssetSpec :
196
+ def get_dashboard_spec (self , data : PowerBITranslatorData ) -> AssetSpec :
190
197
data = check .inst (data , PowerBITranslatorData )
191
198
dashboard_id = data .properties ["id" ]
192
199
tile_report_ids = [
@@ -195,8 +202,7 @@ def get_dashboard_spec(self, data: PowerBIContentData) -> AssetSpec:
195
202
report_keys = [
196
203
self .get_report_spec (
197
204
PowerBITranslatorData (
198
- content_type = data .workspace_data .reports_by_id [report_id ].content_type ,
199
- properties = data .workspace_data .reports_by_id [report_id ].properties ,
205
+ content_data = data .workspace_data .reports_by_id [report_id ],
200
206
workspace_data = data .workspace_data ,
201
207
)
202
208
).key
@@ -224,11 +230,11 @@ def get_dashboard_spec(self, data: PowerBIContentData) -> AssetSpec:
224
230
breaking_version = "1.10" ,
225
231
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
226
232
)
227
- def get_report_asset_key (self , data : PowerBIContentData ) -> AssetKey :
233
+ def get_report_asset_key (self , data : PowerBITranslatorData ) -> AssetKey :
228
234
data = check .inst (data , PowerBITranslatorData )
229
235
return self .get_report_spec (data ).key
230
236
231
- def get_report_spec (self , data : PowerBIContentData ) -> AssetSpec :
237
+ def get_report_spec (self , data : PowerBITranslatorData ) -> AssetSpec :
232
238
data = check .inst (data , PowerBITranslatorData )
233
239
report_id = data .properties ["id" ]
234
240
dataset_id = data .properties .get ("datasetId" )
@@ -238,8 +244,7 @@ def get_report_spec(self, data: PowerBIContentData) -> AssetSpec:
238
244
dataset_key = (
239
245
self .get_semantic_model_spec (
240
246
PowerBITranslatorData (
241
- content_type = dataset_data .content_type ,
242
- properties = dataset_data .properties ,
247
+ content_data = dataset_data ,
243
248
workspace_data = data .workspace_data ,
244
249
)
245
250
).key
@@ -266,19 +271,18 @@ def get_report_spec(self, data: PowerBIContentData) -> AssetSpec:
266
271
breaking_version = "1.10" ,
267
272
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
268
273
)
269
- def get_semantic_model_asset_key (self , data : PowerBIContentData ) -> AssetKey :
274
+ def get_semantic_model_asset_key (self , data : PowerBITranslatorData ) -> AssetKey :
270
275
data = check .inst (data , PowerBITranslatorData )
271
276
return self .get_semantic_model_spec (data ).key
272
277
273
- def get_semantic_model_spec (self , data : PowerBIContentData ) -> AssetSpec :
278
+ def get_semantic_model_spec (self , data : PowerBITranslatorData ) -> AssetSpec :
274
279
data = check .inst (data , PowerBITranslatorData )
275
280
dataset_id = data .properties ["id" ]
276
281
source_ids = data .properties .get ("sources" , [])
277
282
source_keys = [
278
283
self .get_data_source_spec (
279
284
PowerBITranslatorData (
280
- content_type = data .workspace_data .data_sources_by_id [source_id ].content_type ,
281
- properties = data .workspace_data .data_sources_by_id [source_id ].properties ,
285
+ content_data = data .workspace_data .data_sources_by_id [source_id ],
282
286
workspace_data = data .workspace_data ,
283
287
)
284
288
).key
@@ -328,11 +332,11 @@ def get_semantic_model_spec(self, data: PowerBIContentData) -> AssetSpec:
328
332
breaking_version = "1.10" ,
329
333
additional_warn_text = "Use `DagsterPowerBITranslator.get_asset_spec(...).key` instead" ,
330
334
)
331
- def get_data_source_asset_key (self , data : PowerBIContentData ) -> AssetKey :
335
+ def get_data_source_asset_key (self , data : PowerBITranslatorData ) -> AssetKey :
332
336
data = check .inst (data , PowerBITranslatorData )
333
337
return self .get_data_source_spec (data ).key
334
338
335
- def get_data_source_spec (self , data : PowerBIContentData ) -> AssetSpec :
339
+ def get_data_source_spec (self , data : PowerBITranslatorData ) -> AssetSpec :
336
340
data = check .inst (data , PowerBITranslatorData )
337
341
connection_name = (
338
342
data .properties ["connectionDetails" ].get ("path" )
0 commit comments