-
Notifications
You must be signed in to change notification settings - Fork 96
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
Create metricflow-semantics
Package
#1151
Merged
Merged
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
34bb6ff
Add missing `__init__.py` files in `tests`.
plypaul 86420c6
Add semantics module.
plypaul f208ee1
Rename errors.
plypaul c75352d
Rename dataset.
plypaul 678b993
Rename specs.
plypaul e50a1e5
Add missing `__init__.py` in `inference`.
plypaul 8929eec
Move `base_time_grain.py`.
plypaul 614f0e7
Move patterns.
plypaul 2b2ea34
Move spec_classes.py
plypaul 8657abf
Move specs.
plypaul 38f689e
Move naming.
plypaul e9e04f4
Move filters.
plypaul 91529ec
Move model.
plypaul 248474b
Move dag.
plypaul c952eb0
Move dataset.
plypaul 0cc46a3
Move dataflow plan sub-modules.
plypaul 4f28202
Move the rest of dataflow.
plypaul 64cad82
Move some files out of plan_conversion.
plypaul fb53b89
Move plan_conversion.
plypaul d6cbc72
Move errors.
plypaul 02eda1b
Move protocols.
plypaul e1160dd
Move query.
plypaul d80ebc3
Move sql.
plypaul 246b3b0
Move time.
plypaul c7f6a04
Move top level.
plypaul 298b45e
Move collection_helpers.
plypaul d2cd7be
Move mf_logging.
plypaul 5de0abd
Move out time.
plypaul be48a6d
Move out sql.
plypaul 68875ee
Move out protocols/sql_client.
plypaul 8724f02
Move out plan_conversion.
plypaul 9c094dc
Move out dataset.
plypaul 73580a4
Move out dataflow.
plypaul 249cd1b
Move out time.
plypaul 89bef6f
Move out `data_warehouse_model_validator.py`.
plypaul e629e9d
Move `sql_bind_parameters.py.`
plypaul 471a7bd
Update `linkable_spec_resolver.py` to use metric time from DSI.
plypaul 33752c7
Separate and move `SqlJoinType`.
plypaul fce72e9
Move `sql_join_type.py`.
plypaul 2ef2163
Remove `SemanticManifestLookup.time_spine_source`.
plypaul 77bd647
Move semantic tests.
plypaul cfc2eef
Add `metricflow-semantics` package skeleton.
plypaul 58f631c
Move metricflow.semantics.
plypaul 51431b2
Add `tests_metricflow_semantics`.
plypaul 9173de7
Update `snapshot_path_prefix` to handle new test directories.
plypaul f88ad4e
Add `py.typed` for `metricflow_semantics`.
plypaul be48ed5
Move fixtures from `setup_fixtures.py` to `sql_client_fixtures.py`.
plypaul d2094c0
Rename tests -> tests_metricflow.
plypaul 7c17c1e
Update test module name in tests.
plypaul f755143
Split `test_helpers.py` into separate files.
plypaul 5426a61
Move helpers into `test_helpers` module.
plypaul 3d9aba3
Change signature of `assert_snapshot_text_equal` to use `SnapshotConf…
plypaul 2b87c74
Move `load_semantic_manifest` to `manifest_helpers.py`.
plypaul 0313849
Move `semantic_manifest_yamls` to `test_helpers`.
plypaul d6d3cfc
Add `DirectoryAnchor` and use new manifest YAML dir.
plypaul d58a953
Move `assert_*_snapshot*` to `snapshot_helpers`.
plypaul 4c9dda2
Add snapshot methods that don't depend on a SQL client.
plypaul 3e349ff
Change signaure of `assert*` methods to use `SnapshotConfiguration`.
plypaul 7e9ee2c
Initial configuration for `metricflow-semantics` tests.
plypaul 00129ac
Move a few tests to new locations.
plypaul 6f21bb7
Remove `DunderColumnAssociationResolver` from `test_suggestions.py`.
plypaul b988db5
Move `metric_time_dimension.py` to `test_helpers`.
plypaul 3da1773
Remove `DataSet` dependency from `metric_time_dimension.py`
plypaul 76119b6
Separate dataflow validation from `SemanticModelJoinEvaluator`.
plypaul ec9d092
Move semantic tests to `tests_metricflow_semantics`.
plypaul 9b468a9
Move `DunderColumnAssociationResolver` to `metricflow-semantics`.
plypaul d201599
Add `column_association_resolver` fixture.
plypaul ae485c0
Add missing `query_parser` fixture.
plypaul 742b85b
Update `pyproject.toml`.
plypaul d80bf8a
Move tests to `metricflow-semantics`.
plypaul 1699579
Fix pretty_printing for newer Pydantic versions.
plypaul dbf35f8
Update various build-related files.
plypaul f9d3544
Move ID-related objects to `test_helpers``.
plypaul b853369
Move snapshots.
plypaul d54a4ad
Add change log for #1150.
plypaul 4afbd09
Lint fixes.
plypaul f6f64cb
Address comments.
plypaul 9e2c131
Update `DirectoryPathAnchor` to not require `__file__`.
plypaul 60773a9
Update / cleanup build configuration.
plypaul 47d7057
Add package CI tests.
plypaul File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING, List | ||
|
||
from dbt_semantic_interfaces.references import ( | ||
EntityReference, | ||
SemanticModelReference, | ||
) | ||
from metricflow_semantics.instances import EntityInstance, InstanceSet | ||
from metricflow_semantics.mf_logging.pretty_print import mf_pformat | ||
from metricflow_semantics.model.semantics.semantic_model_join_evaluator import SemanticModelJoinEvaluator | ||
|
||
if TYPE_CHECKING: | ||
from metricflow_semantics.model.semantics.semantic_model_lookup import SemanticModelLookup | ||
|
||
|
||
class JoinDataflowOutputValidator: | ||
"""Checks that the instances in the output of a join dataflow node is valid.""" | ||
|
||
def __init__(self, semantic_model_lookup: SemanticModelLookup) -> None: # noqa: D107 | ||
self._join_evaluator = SemanticModelJoinEvaluator(semantic_model_lookup) | ||
|
||
@staticmethod | ||
def _semantic_model_of_entity_in_instance_set( | ||
instance_set: InstanceSet, | ||
entity_reference: EntityReference, | ||
) -> SemanticModelReference: | ||
"""Return the semantic model where the entity was defined in the instance set.""" | ||
matching_instances: List[EntityInstance] = [] | ||
for entity_instance in instance_set.entity_instances: | ||
assert len(entity_instance.defined_from) == 1 | ||
if len(entity_instance.spec.entity_links) == 0 and entity_instance.spec.reference == entity_reference: | ||
matching_instances.append(entity_instance) | ||
|
||
assert len(matching_instances) == 1, ( | ||
f"Not exactly 1 matching entity instances found: {matching_instances} for {entity_reference} in " | ||
f"{mf_pformat(instance_set)}" | ||
) | ||
return matching_instances[0].origin_semantic_model_reference.semantic_model_reference | ||
|
||
def is_valid_instance_set_join( | ||
self, | ||
left_instance_set: InstanceSet, | ||
right_instance_set: InstanceSet, | ||
on_entity_reference: EntityReference, | ||
) -> bool: | ||
"""Return true if the instance sets can be joined using the given entity.""" | ||
return self._join_evaluator.is_valid_semantic_model_join( | ||
left_semantic_model_reference=JoinDataflowOutputValidator._semantic_model_of_entity_in_instance_set( | ||
instance_set=left_instance_set, entity_reference=on_entity_reference | ||
), | ||
right_semantic_model_reference=JoinDataflowOutputValidator._semantic_model_of_entity_in_instance_set( | ||
instance_set=right_instance_set, | ||
entity_reference=on_entity_reference, | ||
), | ||
on_entity_reference=on_entity_reference, | ||
) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be deleting these from the SemanticModelJoinEvaluator now that they've been moved here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thought I deleted that - let me remove it.