uranusjr commented on code in PR #72019: URL: https://github.com/apache/airflow/pull/72019#discussion_r4011588971
########## java-sdk/adr/0002-native-dag-interface.md: ########## @@ -0,0 +1,322 @@ +<!-- + 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. + --> + +# ADR-0002: Native Java Dag — Interface Design + +## Status + +Proposed + +## Context + +A Dag authored with no Python stub file has no `@task.stub` call site to declare its graph, so +Java itself must express the graph, the Dag/task configuration, and the task bodies. This ADR is +scoped to what that Java call site looks like for a user. It also settles the injectable +`client`/`context` question shared with [ADR-0001](0001-mixed-lang-dag-interface.md): they are +**injected as method arguments**, not exposed through getters. It shares the protocol substrate +(the argument-binding spec) with +[`airflow-core/adr/lang-sdk/0007-taskflow-across-language-boundary.md`](../../airflow-core/adr/lang-sdk/0007-taskflow-across-language-boundary.md). + +## Decision + +### Annotation based + +`Client` and `Context` are injected as **method arguments**, exactly as on the mixed-language +surface ([ADR-0001](0001-mixed-lang-dag-interface.md)) — there are no getters and no SDK base class +to extend. A task method's signature is its injected arguments, if any, followed by its data: + +```java [email protected](id = "java_etl", schedule = "@daily") +public class EtlPipeline { // extends nothing of ours; your own base class stays free + + @Builder.Task(id = "extract", retries = 2) + public long extract(Client client) { + return ((Number) client.getVariable("row_count")).longValue(); + } + + @Builder.Task(id = "transform") + public long transform(Client client, Context context, long extracted, double threshold) { + client.setXCom("scaled_in", context.runId); + return (long) (extracted * threshold); + } + + @Builder.Task(id = "load") + public void load(Context context, long transformed) { + log.log(INFO, "Loaded {0} for run {1}", transformed, context.runId); + } + + @Builder.Task(id = "audit") + public void audit(Client client) { /* side effect only, no data in or out */ } + + @Builder.Task(id = "notify") + public void notify(Client client) { /* side effect only, no data in or out */ } + + @Builder.Deps + static class Wiring implements EtlPipelineDeps { + void depends() { + // TaskFlow (data) edges: implied by passing a TaskRef; a constant is wrapped with lit(...) + var rows = extract(); + var scaled = transform(rows, lit(0.9)); + var loaded = load(scaled); + + // non-TaskFlow (ordering-only) edges: sequence with no data flowing + rows.then(audit()); // extract >> audit Review Comment: I think `then` reads much better. If one should change, `after` should be, but I can’t figure out a better alternative. -- 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]
