jason810496 opened a new pull request, #71057:
URL: https://github.com/apache/airflow/pull/71057

   - **note:** Would like to discuss with the user interface as shown in the PR 
description first. No need to go through the implementation as it still depends 
on https://github.com/apache/airflow/pull/69757.
   
   ## Annotation-based native Dag Example
   
   ```java
   @Dag(
       dagId = "java_native_annotation_example",
       description = "Pure-Java Dag authored with annotations, without a Python 
stub file",
       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());
   
     @Task(taskId = "extract", retries = 2)
     public long extract() {
       log.log(INFO, "Extracting a value");
       return 42L;
     }
   
     @Task(taskId = "transform")
     public long transform(long extracted) {
       log.log(INFO, "Transforming {0}", extracted);
       return extracted * 2;
     }
   
     @Task(taskId = "load")
     public void load(long transformed) {
       log.log(INFO, "Loaded {0}", transformed);
     }
   
     @Wiring
     static void depends(AnnotationExampleFlow f) {
       f.load(f.transform(f.extract()));
     }
   }
   ```
   
   ## Interface-based native Dag Example
   
   ```java
   public class InterfaceExample {
     private static final System.Logger log = 
System.getLogger(InterfaceExample.class.getName());
   
     public static class Extract implements TaskFunction {
       @Override
       public void execute(Context context, Client client) {
         log.log(INFO, "Extracting a value");
         client.setXCom(42L);
       }
     }
   
     public static class Transform implements TaskFunction {
       @Override
       public void execute(Context context, Client client) {
         var extracted = ((Number) client.getXCom("extract")).longValue();
         log.log(INFO, "Transforming {0}", extracted);
         client.setXCom(extracted * 2);
       }
     }
   
     public static class Load implements TaskFunction {
       @Override
       public void execute(Context context, Client client) {
         var transformed = client.getXCom("transform");
         log.log(INFO, "Loaded {0}", transformed);
       }
     }
   
     public static DagDef build() {
       var extract =
           new TaskDef("extract", Extract.class)
               .config("retries", 2)
               .config("doc_md", "Extracts a value and pushes it as an XCom.");
       var transform = new TaskDef("transform", 
Transform.class).dependsOn(extract);
       var load = new TaskDef("load", Load.class).dependsOn(transform);
       return new DagDef("java_native_interface_example")
           .config("description", "Pure-Java Dag authored with the interface 
API, without a Python stub file")
           .config("schedule", "@daily")
           .config("catchup", false)
           .config("tags", java.util.List.of("example", "java-sdk"))
           .addTask(extract)
           .addTask(transform)
           .addTask(load);
     }
   }
   ```
   
   ## Mixed language Dag Examples
   
   **annotation** (without Dag or Task level arguments and remove the `@Wiring` 
annotation method)
   ```java
   @Dag(dagId = "java_sdk")
   public class AnnotationExample {
     private static final System.Logger log = 
System.getLogger(AnnotationExample.class.getName());
   
     @Task(taskId = "extract", retries = 2)
     public long extract() {
       log.log(INFO, "Extracting a value");
       return 42L;
     }
   
     @Task(taskId = "transform")
     public long transform(long extracted) {
       log.log(INFO, "Transforming {0}", extracted);
       return extracted * 2;
     }
   
     @Task(taskId = "load")
     public void load(long transformed) {
       log.log(INFO, "Loaded {0}", transformed);
     }
   }
   ```
   
   **interface** (remove all the `.config` and `.dependsOn` calls)
   ```java
   public class InterfaceExample {
   // same as above ...
     public static DagDef build() {
       var extract =
           new TaskDef("extract", Extract.class);
       var transform = new TaskDef("transform", Transform.class);
       var load = new TaskDef("load", Load.class);
       return new DagDef("java_native_interface_example")
           .addTask(extract)
           .addTask(transform)
           .addTask(load);
     }
   }
   ```
   
   ---
   
   ##### Was generative AI tooling used to co-author this PR?
   
   - [x] Yes, with help of Claude Code Fable 5 following [the 
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to