Makoto
05/18/2021, 6:39 PMstate_modified_config_in_test = {"project-dir": PROJECT_DIR, "models": ["state:modified"], "target": "test"}
run_only_changed_models_in_test = dbt_cli_run.configured(state_modified_config_in_test,
name="run_only_changed_models_in_test")
run_all_config_in_test = {"project-dir": PROJECT_DIR, "target": "test"}
run_all_models_in_test = dbt_cli_run.configured(run_all_config_in_test, name="run_all_models_in_test")
I want to be able to conditionally run them depending on if the run
directory exists under the target directory. I read up on conditional branching but what I am not sure how to do is to conditionally invoke one of the dbt solids. I tried using a composite solid to pass in the yielded output but since the dbt solid does not take any input argument, I get the unused input error for the composite solid. Is there a way to work around it or a better way to achieve it?...
@solid(
input_defs=[InputDefinition("start", Nothing)],
output_defs=[OutputDefinition(name="only_modified", is_requried=False),
OutputDefinition(name="all_models", is_requried=False)]
)
def determine_test_dbt_solid_run(context):
<http://context.log.info|context.log.info>("Verifying test target directory exists...")
target_dir = f"{PROJECT_DIR}/target_test/run"
if os.path.isdir(target_dir):
yield Output(True, "only_modified")
else:
yield Output(True, "all_models")
@composite_solid
def run_modified_only(_):
return run_only_changed_models_in_test()
@composite_solid()
def run_all_models(_):
return run_all_models_in_test()
@pipeline
def deploy_dbt_model_pipeline():
only_modified, all_models = determine_test_dbt_solid_run(
copy_target_db_for_testing(
drop_test_db()
)
)
# conditional branching
run_modified_only(only_modified)
run_all_changed(all_models)
I hope what I am trying to achieve makes sense 🙏alex
05/18/2021, 7:35 PMdbt_cli_run
does have a start_after
Nothing
input - if you hook up the dependency to that you should get the behavior you desireMakoto
05/18/2021, 8:09 PMparse_run_results()
in dagster_dbt/cli/utils.py
, since the target directory name is hard coded. I’ll try to think of a way to work around it until the implementation is changed.alex
05/18/2021, 8:11 PMowen
05/18/2021, 8:28 PMrun_modified_only
/ run_all_models
in any downstream solids in the future, and do you care about the asset materializations that are produced from this solid? My first thought is that you might be better off not using the dbt_cli_run
solid at all in this case (I don’t see a clean way of getting around that parse_results() issue you noted). For now, you could instead just create your own solid that invokes execute_cli
directly (https://github.com/dagster-io/dagster/blob/master/python_modules/libraries/dagster-dbt/dagster_dbt/cli/utils.py#L16).Makoto
05/18/2021, 9:13 PMstate
method (link to doc), which resulted me to create separate directories for default and test targets so that I can keep things separate. In my dbt project yml, I have target-path set to:
target-path: target_{{ target.name }}
I’m still somewhat new to dagster and not super familiar with asset materializations, but I read up on it real quick and I don’t think I will be using it for now.
I think you are right that I should go with execute_cli
for now. Thanks for link.
Just thinking out loud… It seems like we could add another config key value pair for overwriting the target path for config dictionary for dbt solid. 🤔 That seems like a simple/safe change. Happy to collaborate with you to author a PR.def parse_run_results(path: str)
would take another argument, so it looks something like:
def parse_run_results(path: str, target_dir="target")
and in solids.py, we can call it like:
target_dir = "target"
if context.solid_config["target-dir"]:
target_dir = context.solid_config["target-dir"]
run_results = parse_run_results(context.solid_config["project-dir"], target_dir)
maybe?parse_run_results
is also being used in dbt_cli_test
solid, which I use so I’m motived to get the changes in 😄 . Let me know what you think.owen
05/18/2021, 10:30 PM