Skip to content

How can I merge conditional branches? #5718

Answered by sryza
sryza asked this question in Q&A
Discussion options

You must be logged in to vote

Here's an example:

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])

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sryza
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant