Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiple semantic models with generated metrics #10451

Merged
merged 7 commits into from
Jul 17, 2024

Conversation

gshank
Copy link
Contributor

@gshank gshank commented Jul 16, 2024

resolves #10450

Problem

When partial parsing, all generated metrics in a file were being deleted instead of just for the changed semantic model.

Solution

Use a dictionary in SchemaSourceFile, with the semantic model name for the key and a list containing metric unique ids for the value.

Checklist

  • I have read the contributing guide and understand what's expected of me
  • I have run this code in development and it appears to resolve the stated issue
  • This PR includes tests, or tests are not required/relevant for this PR
  • This PR has no interface changes (e.g. macros, cli, logs, json artifacts, config files, adapter interface, etc) or this PR has already received feedback and approval from Product or DX
  • This PR includes type annotations for new and modified functions

@gshank gshank requested a review from a team as a code owner July 16, 2024 17:41
@cla-bot cla-bot bot added the cla:yes label Jul 16, 2024
Copy link

codecov bot commented Jul 16, 2024

Codecov Report

Attention: Patch coverage is 89.18919% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.76%. Comparing base (b032915) to head (cff48c1).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10451      +/-   ##
==========================================
- Coverage   88.79%   88.76%   -0.03%     
==========================================
  Files         180      180              
  Lines       22562    22586      +24     
==========================================
+ Hits        20034    20049      +15     
- Misses       2528     2537       +9     
Flag Coverage Δ
integration 85.99% <56.75%> (-0.08%) ⬇️
unit 62.13% <54.05%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
Unit Tests 62.13% <54.05%> (+0.02%) ⬆️
Integration Tests 85.99% <56.75%> (-0.08%) ⬇️

Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reproducing this and adding the fix!
Understanding what's going on here is a bit tricky, can we add a bit more comments? And maybe do a live walk through with the team to pass the knowledge along?
Maybe this is because I am not familiar with how this section of the logic works.
(sorry I meant to comment vs approve, clicked the wrong button).

def fix_metrics_from_measures(self):
# Loop through yaml dictionary looking for matching generated metrics
generated_metrics = self.generated_metrics
self.generated_metrics = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using this manipulation of generated_metrics to avoid fix_metrics_from_measures and fix_metrics_from_measures infinite looping? Can we try to organize the function so it is easier to read?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add some unittest to test this new logic added? I see the coverage is only 10%-ish.

self.delete_disabled(unique_id, schema_file.file_id)
if schema_file.generated_metrics:
schema_file.fix_metrics_from_measures()
if semantic_model_name in schema_file.metrics_from_measures:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a bit of comment here?

@@ -146,3 +147,28 @@ def test_semantic_model_flipping_create_metric_partial_parsing(self, project):
# Verify the metric originally created by `create_metric: true` was removed
metric = result.result.metrics[generated_metric]
assert metric.name == "txn_revenue"


class TestSemanticModelPartialParsingGeneratedMetrics:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice re-pro case!!!

@ChenyuLInx ChenyuLInx self-requested a review July 16, 2024 23:11
Copy link
Contributor

@ChenyuLInx ChenyuLInx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am following this time! Thanks a lot for the comment and explanation!

@@ -968,13 +968,17 @@ def delete_schema_semantic_model(self, schema_file, semantic_model_dict):
elif unique_id in self.saved_manifest.disabled:
self.delete_disabled(unique_id, schema_file.file_id)

metrics = schema_file.generated_metrics.copy()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So here we were deleting all generated metrics instead of just the one related to a semantic model

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct.

@gshank gshank merged commit 471b816 into main Jul 17, 2024
64 of 66 checks passed
@gshank gshank deleted the multiple_semantic_models_with_generated_metrics branch July 17, 2024 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Partial parsing issue with generated metrics on multiple semantic models in the same file
2 participants