henry3260 commented on code in PR #71188:
URL: https://github.com/apache/airflow/pull/71188#discussion_r4090305111
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/Bundle.kt:
##########
@@ -31,17 +33,74 @@ package org.apache.airflow.sdk
class Bundle(
dags: Iterable<DagDef>,
) {
- internal val dags: Map<String, DagDef> = dags.associateByDagId()
-}
+ internal val dags = linkedMapOf<String, DagDef>()
+
+ /** Creates an empty bundle to [register] into. */
+ constructor() : this(emptyList())
+
+ init {
+ dags.forEach { register(it) }
+ }
-private fun Iterable<DagDef>.associateByDagId(): Map<String, DagDef> {
- val dagMap = linkedMapOf<String, DagDef>()
- for (dag in this) {
- require(dagMap.putIfAbsent(dag.id, dag) == null) {
+ /**
+ * Registers a Dag.
+ *
+ * @return This bundle, for chaining.
+ * @throws IllegalArgumentException if another Dag shares its ID.
+ */
+ fun register(dag: DagDef): Bundle {
+ require(dags.putIfAbsent(dag.id, dag) == null) {
"Dags in bundle have duplicate ID: ${dag.id}"
Review Comment:
Not sure if this is a realistic scenario, but if a user does:
```java
bundle.register("java_etl", "report", Report.class);
bundle.register(dag); // dag.id == "java_etl"
```
the second call fails with `Dags in bundle have duplicate ID: ${dag.id}`,
because `register(dagId, taskId, def)` already created a `DagDef("java_etl")`
via `getOrPut`.
Is failing the intended behavior here? Or should `register(dag)` merge into
an existing DagDef with the same id instead of rejecting it? If it is not a
real case, feel free to resolve!
##########
java-sdk/sdk/src/main/kotlin/org/apache/airflow/sdk/Bundle.kt:
##########
@@ -31,17 +33,74 @@ package org.apache.airflow.sdk
class Bundle(
dags: Iterable<DagDef>,
) {
- internal val dags: Map<String, DagDef> = dags.associateByDagId()
-}
+ internal val dags = linkedMapOf<String, DagDef>()
Review Comment:
Since Bundle is now mutable, could we reject `register()` once `serve() `has
started? The Go SDK does this on main: serve sets `closed` first thing and
Register panics with `"Serve has already been called; register everything
before Serve"`.
--
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]