https://dagster.io/ logo
#ask-community
Title
# ask-community
t

Tadas Barzdžius

11/18/2021, 12:44 PM
How should I execute an op with result from either of conditional op result?
Copy code
@job
def job() -> None:
    query, file = check_input_type()

    file_path = generate_file(query)
    file_path = get_file(file)

    process_file(file_path)
Or other way of asking question - how should I merge conditional branches back? Something similar like here: https://docs.prefect.io/core/idioms/conditional.html#merging-branches-in-a-flow
s

sandy

11/18/2021, 6:53 PM
Hi @Tadas Barzdžius - here's an example of merging conditional branches:
Copy code
import random

from dagster import Out, Output, job, op


@op(out={"branch_1": Out(is_required=False), "branch_2": Out(is_required=False)})
def branching_op():
    num = random.randint(0, 1)
    if num == 0:
        yield Output(1, "branch_1")
    else:
        yield Output(2, "branch_2")


@op
def branch_1_op(input1):
    return input1


@op
def branch_2_op(input1):
    return input1


@op
def merge(input1):
    assert input1 == [1] or input1 == [2]


@job
def branching():
    branch_1, branch_2 = branching_op()
    r1 = branch_1_op(branch_1)
    r2 = branch_2_op(branch_2)
    merge([r1, r2])
I created a github discussion to track this for posterity: https://github.com/dagster-io/dagster/discussions/5718
t

Tadas Barzdžius

11/19/2021, 10:20 AM
@sandy thanks!
9 Views