jason810496 commented on code in PR #71188:
URL: https://github.com/apache/airflow/pull/71188#discussion_r4091613758


##########
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:
   Yes we should handle this scenario, the TS SDK did validate against this 
case.



##########
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:
   Yes, we should implement this guard like Go side.



-- 
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