-
Notifications
You must be signed in to change notification settings - Fork 1
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
b1efe8b
commit 7b2dc4d
Showing
6 changed files
with
465 additions
and
394 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
__pycache__/ | ||
.pytest_cache/ | ||
.env | ||
tap-*.json | ||
tap-*.json | ||
tmp* |
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 |
---|---|---|
@@ -1,25 +1,83 @@ | ||
from typing import List | ||
from elx import Runner, Tap, Target | ||
from elx.catalog import Stream | ||
from dagster import AssetsDefinition, asset | ||
from typing import Generator, List | ||
from elx import Runner | ||
from dagster import ( | ||
AssetsDefinition, | ||
Nothing, | ||
OpExecutionContext, | ||
Output, | ||
multi_asset, | ||
AssetOut, | ||
get_dagster_logger, | ||
) | ||
from elx.extensions.dagster.utils import dagster_safe_name, generate_description | ||
|
||
logger = get_dagster_logger() | ||
|
||
|
||
def load_assets(runner: Runner) -> List[AssetsDefinition]: | ||
def run_factory(runner: Runner, stream: Stream): | ||
def run(context): | ||
runner.run(stream=stream.name) | ||
return dagster_safe_name(stream.name) | ||
""" | ||
Load the assets for a runner, each asset represents one tap target combination. | ||
Args: | ||
runner (Runner): The runner to extract from. | ||
Returns: | ||
List[AssetsDefinition]: The assets. | ||
""" | ||
|
||
def run_factory(runner: Runner) -> callable: | ||
""" | ||
Create a run function for a runner. | ||
Args: | ||
runner (Runner): The runner to create a run function for. | ||
Returns: | ||
callable: The run function that gets executed by Dagster. | ||
""" | ||
|
||
def run(context: OpExecutionContext) -> Generator[Output, None, None]: | ||
""" | ||
Run a tap target combination. | ||
Args: | ||
context (OpExecutionContext): The context to run in. | ||
Yields: | ||
Generator[Output, None, None]: The names of the selected outputs. | ||
""" | ||
# Execute the runner and yield the selected outputs. | ||
runner.run( | ||
streams=list(context.selected_output_names), | ||
logger=logger, | ||
) | ||
|
||
for context_output_name in context.selected_output_names: | ||
yield Output( | ||
value=Nothing, | ||
output_name=context_output_name, | ||
metadata={ | ||
"state_path": f"{runner.state_manager.base_path}/{runner.state_file_name}", | ||
"state": runner.load_state(), | ||
}, | ||
) | ||
|
||
return run | ||
|
||
return [ | ||
asset( | ||
name=dagster_safe_name(stream.name), | ||
key_prefix=dagster_safe_name(runner.tap.executable), | ||
description=generate_description(runner=runner, stream=stream), | ||
multi_asset( | ||
name=f"run_{dagster_safe_name(runner.tap.executable)}_{dagster_safe_name(runner.target.executable)}", | ||
outs={ | ||
dagster_safe_name(stream.name): AssetOut( | ||
is_required=False, | ||
description=generate_description(runner=runner, stream=stream), | ||
key_prefix=dagster_safe_name(runner.tap.executable), | ||
code_version=runner.tap.hash_key, | ||
) | ||
for stream in runner.tap.streams | ||
}, | ||
can_subset=True, | ||
group_name=dagster_safe_name(runner.tap.executable), | ||
compute_kind="python", | ||
)(run_factory(runner, stream)) | ||
for stream | ||
in runner.tap.streams | ||
] | ||
)(run_factory(runner)) | ||
] |
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
Oops, something went wrong.