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

fahad

03/29/2022, 5:40 PM
Hey all, Had a question about using the outputs from two ops that are involved in a conditional branch. If I wanted either the output from branch 1 or branch 2 to kick off a downstream op, is it possible to define that in a graph/job? Seems like it might break the model of data driven execution.
Copy code
@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(_input):
    return "hello"
@op
def branch_2_op(_input):
    return "world"
@op
def another_op(_input):
    pass
@job
def branching():
    branch_1, branch_2 = branching_op()
    returned_string_1 = branch_1_op(branch_1)
    returned_string_2 = branch_2_op(branch_2)
    another_op( ??? ) # should take in either returned_string_1 or returned_string_2
o

owen

03/29/2022, 5:46 PM
hi @fahad! the way to do this would be
another_op([returned_string_1, returned_string_2])
. At runtime, optional outputs that do not get fired will not be part of the list (so, the way it's defined right now, this list would always have a single element at runtime). Inside another_op, you can safely just take the first element of the input list and carry on from there.
f

fahad

03/29/2022, 5:46 PM
Awesome, thank you!
🎉 2
2 Views