-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84016bd
commit d7d5597
Showing
11 changed files
with
132 additions
and
0 deletions.
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 @@ | ||
from internal.domain.task.entities.dd.dd_task import DdTask # noqa: F401 |
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,48 @@ | ||
from desbordante.dd.algorithms import Split | ||
from internal.domain.task.entities.task import Task | ||
from internal.domain.task.value_objects import PrimitiveName, IncorrectAlgorithmName | ||
from internal.domain.task.value_objects.dd import DdTaskConfig, DdTaskResult | ||
from internal.domain.task.value_objects.dd import DdAlgoName, DdModel, DdAlgoResult | ||
|
||
|
||
class DdTask(Task[Split, DdTaskConfig, DdTaskResult]): | ||
""" | ||
Task class for discovering Data Dependencies (DD). | ||
This class handles the execution of the DD algorithm and formats | ||
the results for further processing. | ||
Methods: | ||
- _match_algo_by_name(algo_name: DdAlgoName) -> Split: | ||
Match the DD algorithm by its name. | ||
- _collect_result(algo: Split) -> DdTaskResult: | ||
Process the output of the DD algorithm and return the result. | ||
""" | ||
|
||
def _collect_result(self, algo: Split) -> DdTaskResult: | ||
""" | ||
Collect and process the DD result. | ||
Args: | ||
algo (Split): DD algorithm instance to process. | ||
Returns: | ||
DdTaskResult: The processed result containing data dependencies. | ||
""" | ||
dds = algo.get_dds() | ||
algo_result = DdAlgoResult(dds=[DdModel.from_dd(dd) for dd in dds]) | ||
return DdTaskResult(primitive_name=PrimitiveName.dd, result=algo_result) | ||
|
||
def _match_algo_by_name(self, algo_name: str) -> Split: | ||
""" | ||
Match the DD algorithm by name. | ||
Args: | ||
algo_name (DdAlgoName): The name of the DD algorithm. | ||
Returns: | ||
Split: The corresponding algorithm instance. | ||
""" | ||
match algo_name: | ||
case DdAlgoName.Split: | ||
return Split() | ||
case _: | ||
raise IncorrectAlgorithmName(algo_name, "DD") |
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,23 @@ | ||
from typing import Literal | ||
|
||
from pydantic import BaseModel | ||
|
||
from internal.domain.task.value_objects.primitive_name import PrimitiveName | ||
from internal.domain.task.value_objects.dd.algo_config import OneOfDdAlgoConfig | ||
from internal.domain.task.value_objects.dd.algo_result import ( # noqa: F401 | ||
DdAlgoResult, | ||
DdModel, | ||
) | ||
from internal.domain.task.value_objects.dd.algo_name import DdAlgoName # noqa: F401 | ||
|
||
|
||
class BaseDdTaskModel(BaseModel): | ||
primitive_name: Literal[PrimitiveName.dd] | ||
|
||
|
||
class DdTaskConfig(BaseDdTaskModel): | ||
config: OneOfDdAlgoConfig | ||
|
||
|
||
class DdTaskResult(BaseDdTaskModel): | ||
result: DdAlgoResult |
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,28 @@ | ||
from typing import Literal, Annotated | ||
from pydantic import Field | ||
from internal.domain.common import OptionalModel | ||
from internal.domain.task.value_objects.dd.algo_name import DdAlgoName | ||
from internal.domain.task.value_objects.dd.algo_descriptions import descriptions | ||
|
||
|
||
class BaseDdConfig(OptionalModel): | ||
__non_optional_fields__ = { | ||
"algo_name", | ||
} | ||
|
||
|
||
class SplitConfig(BaseDdConfig): | ||
algo_name: Literal[DdAlgoName.Split] | ||
|
||
num_rows: Annotated[int, Field(ge=1, description=descriptions["num_rows"])] | ||
num_columns: Annotated[int, Field(ge=1, description=descriptions["num_columns"])] | ||
# TODO: diff table is not string | ||
difference_table: Annotated[ | ||
str, Field(description=descriptions["difference_table"]) | ||
] | ||
|
||
|
||
OneOfDdAlgoConfig = Annotated[ | ||
SplitConfig, | ||
Field(discriminator="algo_name"), | ||
] |
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,5 @@ | ||
descriptions = { | ||
"num_rows": "Number of rows from the dataset to process", | ||
"num_columns": "Number of columns from the dataset to process", | ||
"difference_table": "CSV table with difference limits for each column", | ||
} |
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,5 @@ | ||
from enum import StrEnum, auto | ||
|
||
|
||
class DdAlgoName(StrEnum): | ||
Split = auto() |
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,14 @@ | ||
from pydantic import BaseModel | ||
from desbordante.dd import DD | ||
|
||
|
||
class DdModel(BaseModel): | ||
description: str | ||
|
||
@classmethod | ||
def from_dd(cls, dd: DD): | ||
return cls(description=str(dd)) | ||
|
||
|
||
class DdAlgoResult(BaseModel): | ||
dds: list[DdModel] |
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