microsoft / semantic-link-labs

Early access to new features for Microsoft Fabric's Semantic Link.
MIT License
178 stars 37 forks source link

run_model_bpa_bulk gives error CalculatedColumn' object has no attribute 'SourceColumn #273

Closed Jai-Prakash-HU closed 1 week ago

Jai-Prakash-HU commented 1 week ago

run_model_bpa_bulk gives error CalculatedColumn' object has no attribute 'SourceColumn

We checked it, we do not have any calculated column in dataset which has error. Above problem I am facing is with many datasets. Example out of 50 dataset I found this problem in 10 datasets. It does not collect any data after throwing this error

Collecting Model BPA stats for the 'CHC_PIPE' semantic model within the 'PBI_DMRDXXXXXXXXXXX' workspace. 🔴 Model BPA failed for the 'CHC_PIPE' semantic model within the 'PBI_DMRDXXXXXXXXXXX' workspace. 'CalculatedColumn' object has no attribute 'SourceColumn' ⌛ Saving the Model BPA results of the 'PBI_DMRDXXXXXXXXXXXX' workspace to the 'modelbparesults' within the 'data_powerbi_platform' lakehouse within the 'XXXXXXXXXXXXXX' workspace...

Image

m-kovalsky commented 1 week ago

What happens when you run the 'run_model_bpa' function against the CHC_PIPE semantic model?

Jai-Prakash-HU commented 1 week ago

labs.run_model_bpa(dataset = 'CHC_PIPE', workspace = 'PBI_DMRD_DEV_CHC_PPIPE')

results are as belwo:

AttributeError Traceback (most recent call last) Cell In[13], line 1 ----> 1 labs.run_model_bpa(dataset = 'CHC_PIPE', workspace = 'PBI_DMRD_DEV_CHC_PPIPE')

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy/_utils/_log.py:310, in mds_log..get_wrapper..log_decorator_wrapper(*args, *kwargs) 307 raise 309 try: --> 310 result = func(args, **kwargs) 312 # The invocation for get_message_dict moves after the function 313 # so it can access the state after the method call 314 message.update(extractor.get_completion_message_dict(result, arg_dict))

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy_labs/_model_bpa.py:293, in run_model_bpa(dataset, rules, workspace, export, return_dataframe, extended, language, **kwargs) 291 x = [nm(obj) for obj in tom.all_hierarchies() if expr(obj, tom)] 292 elif scope == "Table": --> 293 x = [nm(obj) for obj in tom.model.Tables if expr(obj, tom)] 294 elif scope == "Relationship": 295 x = [nm(obj) for obj in tom.model.Relationships if expr(obj, tom)]

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy_labs/_model_bpa.py:293, in (.0) 291 x = [nm(obj) for obj in tom.all_hierarchies() if expr(obj, tom)] 292 elif scope == "Table": --> 293 x = [nm(obj) for obj in tom.model.Tables if expr(obj, tom)] 294 elif scope == "Relationship": 295 x = [nm(obj) for obj in tom.model.Relationships if expr(obj, tom)]

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy_labs/_model_bpa_rules.py:244, in model_bpa_rules..(obj, tom) 34 print( 35 "The 'workspace' parameter has been deprecated. Please remove this parameter from the function going forward." 36 ) 37 del kwargs["workspace"] 39 rules = pd.DataFrame( 40 [ 41 ( 42 "Performance", 43 "Column", 44 "Warning", 45 "Do not use floating point data types", 46 lambda obj, tom: obj.DataType == TOM.DataType.Double, 47 'The "Double" floating point data type should be avoided, as it can result in unpredictable roundoff errors and decreased performance in certain scenarios. Use "Int64" or "Decimal" where appropriate (but note that "Decimal" is limited to 4 digits after the decimal sign).', 48 ), 49 ( 50 "Performance", 51 "Column", 52 "Warning", 53 "Avoid using calculated columns", 54 lambda obj, tom: obj.Type == TOM.ColumnType.Calculated, 55 "Calculated columns do not compress as well as data columns so they take up more memory. They also slow down processing times for both the table as well as process recalc. Offload calculated column logic to your data warehouse and turn these calculated columns into data columns.", 56 "https://www.elegantbi.com/post/top10bestpractices", 57 ), ............XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX>>>>>>>>>>>>>>>>>>>>

      "Formatting",
809             ["Table", "Column", "Measure", "Partition", "Hierarchy"],
810             "Info",
811             "First letter of objects must be capitalized",
812             lambda obj, tom: obj.Name[0] != obj.Name[0].upper(),
813             "The first letter of object names should be capitalized to maintain professional quality.",
814         ),
815         (
816             "Naming Conventions",
817             ["Table", "Column", "Measure", "Partition", "Hierarchy"],
818             "Warning",
819             "Object names must not contain special characters",
820             lambda obj, tom: re.search(r"[\t\r\n]", obj.Name),
821             "Object names should not include tabs, line breaks, etc.",
822         ),
823     ],
824     columns=[
825         "Category",
826         "Scope",
827         "Severity",
828         "Rule Name",
829         "Expression",
830         "Description",
831         "URL",
832     ],
833 )
835 return rules

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy_labs/tom/_model.py:2280, in TOMWrapper.is_field_parameter(self, table_name) 2270 import Microsoft.AnalysisServices.Tabular as TOM 2272 t = self.model.Tables[table_name] 2274 return ( 2275 any( 2276 p.SourceType == TOM.PartitionSourceType.Calculated 2277 and "NAMEOF(" in p.Source.Expression 2278 for p in t.Partitions 2279 ) -> 2280 and all( 2281 "[Value" in c.SourceColumn 2282 for c in t.Columns 2283 if c.Type != TOM.ColumnType.RowNumber 2284 ) 2285 and t.Columns.Count == 4 2286 )

File ~/cluster-env/clonedenv/lib/python3.11/site-packages/sempy_labs/tom/_model.py:2281, in (.0) 2270 import Microsoft.AnalysisServices.Tabular as TOM 2272 t = self.model.Tables[table_name] 2274 return ( 2275 any( 2276 p.SourceType == TOM.PartitionSourceType.Calculated 2277 and "NAMEOF(" in p.Source.Expression 2278 for p in t.Partitions 2279 ) 2280 and all( -> 2281 "[Value" in c.SourceColumn 2282 for c in t.Columns 2283 if c.Type != TOM.ColumnType.RowNumber 2284 ) 2285 and t.Columns.Count == 4 2286 )

AttributeError: 'CalculatedColumn' object has no attribute 'SourceColumn'

m-kovalsky commented 1 week ago

I believe the issue is with the is_field_paramter in the TOMWrapper. Do you have a calculated table which uses the NAMEOF function? And this table also has a calculated column? Can you share more on this so I can make the appropriate fix?

Jai-Prakash-HU commented 1 week ago

yes, I have a calculated table using NAMEOF function and it also has a calculated column.

Image

m-kovalsky commented 1 week ago

Thanks. I've put a fix in place for the next release.

m-kovalsky commented 1 week ago

Fixed in 0.8.5.