-
Notifications
You must be signed in to change notification settings - Fork 167
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
added new groups #1667
Merged
Merged
added new groups #1667
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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,31 @@ | ||
from typing import Dict, Generic, List, Optional, TypeVar, Union | ||
|
||
T = TypeVar("T") | ||
TreeT = Dict[str, Union[List[T], "TreeT"]] | ||
|
||
|
||
class TreeBuilder(Generic[T]): | ||
def __init__(self, seperator: str, files_keywork: str = "__files__") -> None: | ||
self.seperator = seperator | ||
self.files_keywork = files_keywork | ||
self._tree: TreeT = {} | ||
|
||
def add(self, path: Optional[str], data: Optional[T]) -> None: | ||
if path is None or data is None: | ||
return | ||
parts = path.split(self.seperator) | ||
current: dict = self._tree | ||
for part in parts[:-1]: | ||
if isinstance(current, list): | ||
raise ValueError( | ||
f"Path parts cannot contain files keyword: {self.files_keywork}" | ||
) | ||
current = current.setdefault(part, {}) | ||
if self.files_keywork in current: | ||
if id not in current[self.files_keywork]: | ||
current[self.files_keywork].append(data) | ||
else: | ||
current[self.files_keywork] = [data] | ||
|
||
def get_tree(self) -> TreeT: | ||
return self._tree |
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 |
---|---|---|
@@ -1,9 +1,10 @@ | ||
from collections import defaultdict | ||
from typing import Dict, List, Optional, Tuple, Union | ||
from typing import Dict, Iterable, List, Optional, Tuple, Union | ||
|
||
from elementary.clients.api.api_client import APIClient | ||
from elementary.monitor.api.filters.filters import FiltersAPI | ||
from elementary.monitor.api.groups.groups import GroupsAPI | ||
from elementary.monitor.api.groups.schema import GroupsSchema | ||
from elementary.monitor.api.invocations.invocations import InvocationsAPI | ||
from elementary.monitor.api.lineage.lineage import LineageAPI | ||
from elementary.monitor.api.models.models import ModelsAPI | ||
|
@@ -30,10 +31,23 @@ | |
from elementary.monitor.api.tests.tests import TestsAPI | ||
from elementary.monitor.api.totals_schema import TotalsSchema | ||
from elementary.monitor.data_monitoring.schema import SelectorFilterSchema | ||
from elementary.monitor.fetchers.tests.schema import NormalizedTestSchema | ||
from elementary.utils.time import get_now_utc_iso_format | ||
|
||
|
||
class ReportAPI(APIClient): | ||
def _get_groups( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. separated into a function to make it possible to easily overwrite in cloud |
||
self, | ||
models: Iterable[NormalizedModelSchema], | ||
sources: Iterable[NormalizedSourceSchema], | ||
exposures: Iterable[NormalizedExposureSchema], | ||
singular_tests: Iterable[NormalizedTestSchema], | ||
) -> GroupsSchema: | ||
groups_api = GroupsAPI(self.dbt_runner) | ||
return groups_api.get_groups( | ||
artifacts=[*models, *sources, *exposures, *singular_tests] | ||
) | ||
|
||
def get_report_data( | ||
self, | ||
days_back: int = 7, | ||
|
@@ -59,7 +73,6 @@ def get_report_data( | |
invocations_per_test=test_runs_amount, | ||
) | ||
models_api = ModelsAPI(dbt_runner=self.dbt_runner) | ||
groups_api = GroupsAPI(dbt_runner=self.dbt_runner) | ||
lineage_api = LineageAPI(dbt_runner=self.dbt_runner) | ||
filters_api = FiltersAPI(dbt_runner=self.dbt_runner) | ||
invocations_api = InvocationsAPI(dbt_runner=self.dbt_runner) | ||
|
@@ -73,13 +86,8 @@ def get_report_data( | |
lineage_node_ids.extend(exposures.keys()) | ||
singular_tests = tests_api.get_singular_tests() | ||
|
||
groups = groups_api.get_groups( | ||
artifacts=[ | ||
*models.values(), | ||
*sources.values(), | ||
*exposures.values(), | ||
*singular_tests, | ||
] | ||
groups = self._get_groups( | ||
models.values(), sources.values(), exposures.values(), singular_tests | ||
) | ||
|
||
models_runs = models_api.get_models_runs( | ||
|
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.
basically the logic from
_update_dbt_group
extracted to a generic class