Repository navigation
Java SDK: Declare a Dag's task graph with @Builder.Deps #71189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jason810496
merged 13 commits into
apache:main
from
jason810496:feature/java-sdk-native-dag
Oct 6, 2026
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ae1640
Java SDK: Declare a Dag's task graph with @Builder.Deps
jason810496 8d92b50
Java SDK: Quote wired task ids as Java string literals
jason810496 2e4bec7
Java SDK: Validate the @Builder.Deps class at compile time
jason810496 79e3395
Java SDK: Reject task method names that clash with the wiring view
jason810496 202e9c7
Java SDK: Type a wired numeric input by its parameter's own type
jason810496 37a0765
Java SDK: Register both the Dag and handlers of a class, unwrapping b…
jason810496 14c180a
Java SDK: Reject a raw null wiring argument and test the recorder's g…
jason810496 4dadc5d
Java SDK: Reword the native-Dag docs without em-dashes
jason810496 0dc60cd
Java SDK: Drop Bundle tests that repeat existing coverage
jason810496 23be1d0
Java SDK: Require a @Builder.Deps class on every @Builder.Dag class
jason810496 c394f9d
Java SDK: Back the k8s test's stub tasks with task handlers
jason810496 162a3ff
Java SDK: Reject overloaded task and task-handler methods
jason810496 ff8ec8f
Java SDK: Fix the Dag examples a required wiring class invalidates
jason810496 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
java-sdk/example/src/java/org/apache/airflow/example/nativedag/AnnotationExample.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| // "native" is a Java keyword, so the native-Dag examples live in "nativedag". | ||
| package org.apache.airflow.example.nativedag; | ||
|
|
||
| import static java.lang.System.Logger.Level.INFO; | ||
|
|
||
| import org.apache.airflow.sdk.*; | ||
|
|
||
| // A Dag defined entirely in Java, annotation-style. The @Builder.Dag and | ||
| // @Builder.Task attributes carry the configuration and the @Builder.Deps class | ||
| // declares the graph -- the single place dependencies are defined. | ||
| @Builder.Dag( | ||
| id = "java_native_annotation_example", | ||
| description = "Pure-Java Dag authored with annotations", | ||
| schedule = "@daily", | ||
| startDate = "2026-01-01T00:00:00Z", | ||
| catchup = false, | ||
| tags = {"example", "java-sdk"}) | ||
| public class AnnotationExample { | ||
| private static final System.Logger log = System.getLogger(AnnotationExample.class.getName()); | ||
|
|
||
| @Builder.Task(id = "extract", retries = 2) | ||
| public long extract() { | ||
| log.log(INFO, "Extracting a value"); | ||
| return 42L; | ||
| } | ||
|
|
||
| @Builder.Task(id = "transform") | ||
| public long transform(long extracted, double factor) { | ||
| log.log(INFO, "Transforming {0} by {1}", extracted, factor); | ||
| return (long) (extracted * factor); | ||
| } | ||
|
|
||
| @Builder.Task(id = "load") | ||
| public void load(long transformed) { | ||
| log.log(INFO, "Loaded {0}", transformed); | ||
| } | ||
|
|
||
| @Builder.Task(id = "audit") | ||
| public void audit() { | ||
| log.log(INFO, "Audited the run"); | ||
| } | ||
|
|
||
| // Implements the generated wiring view, so javac type-checks the graph: | ||
| // extract() yields a TaskRef<Long>, which is an Arg<Long> for transform. | ||
| @Builder.Deps | ||
| static class Wiring implements AnnotationExampleDeps { | ||
| void depends() { | ||
| var extracted = extract(); | ||
| load(transform(extracted, lit(1.5))); | ||
| // Ordering-only edge: audit runs after extract, with no data flowing. | ||
| extracted.before(audit()); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.