Skip to content

Go SDK: add dag.Switch with Case for multi-way branching - #74321

Merged
jason810496 merged 2 commits into
apache:mainfrom
FrankYang0529:airflow-go-sdk-dag-switch
Oct 6, 2026
Merged

jason810496 merged 2 commits into
apache:mainfrom
FrankYang0529:airflow-go-sdk-dag-switch

Conversation

@FrankYang0529

Copy link
Copy Markdown
Member

Implement Go SDK: Add dag.Switch with Case.

  • dag.Switch(fn, opts...) and TaskGroupRef.Switch add a task that runs the decider function fn, and return an *airflow.SwitchRef. fn returns (*airflow.TaskRef, error).
  • SwitchRef.Case(task) names a task that the decider can choose and records the edge from the decider to that task. Case returns the switch, so one statement can name every case: dag.Switch(pickPath).Case(long).Case(short).
  • When the decider returns a case, the decider task pushes the task_id of that case as its own return_value XCom. The decider task then writes the task_ids of the other cases to the skipmixin_key XCom and skips those cases.
  • When the decider returns a *airflow.TaskRef that is not a case, the decider task fails and pushes no XCom.

Was generative AI tooling used to co-author this PR?
  • Yes - Claude Code

  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review, LGTM overall.
Here're some comments from the claude review.

Comment thread go-sdk/airflow/switch.go
Comment thread go-sdk/internal/bundle/task.go Outdated
Comment thread go-sdk/airflow/dag.go
Signed-off-by: PoAn Yang <payang@apache.org>
Signed-off-by: PoAn Yang <payang@apache.org>
@FrankYang0529
FrankYang0529 force-pushed the airflow-go-sdk-dag-switch branch from 4b3fbde to e04fb09 Compare October 6, 2026 08:47

@jason810496 jason810496 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@jason810496
jason810496 marked this pull request as ready for review October 6, 2026 11:17
@jason810496
jason810496 merged commit a13edb4 into apache:main Oct 6, 2026
90 of 91 checks passed
@FrankYang0529
FrankYang0529 deleted the airflow-go-sdk-dag-switch branch October 6, 2026 12:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants