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


##########
ts-sdk/src/sdk/dag.ts:
##########
@@ -508,6 +639,70 @@ export class Dag {
     return spec as TaskSpec;
   }
 
+  #addGroup(parentGroupId: string | undefined, groupId: string): TaskGroupRef {
+    if (typeof groupId !== "string" || groupId.length === 0) {
+      throw new Error(`A task group of Dag "${this.dagId}" must have a 
non-empty ID`);
+    }
+    if (groupId.includes(GROUP_SEPARATOR)) {
+      // The separator is what joins a group to what it holds, so one inside an
+      // ID would make the resulting task id ambiguous.
+      throw new Error(
+        `Task group ID "${groupId}" of Dag "${this.dagId}" cannot contain ` +
+          `"${GROUP_SEPARATOR}"; nest groups with taskGroup(...) instead`,
+      );
+    }
+    if (this.#finalized) {
+      throw new Error(
+        `Task group "${groupId}" cannot be added to Dag "${this.dagId}" after 
the Dag was read; ` +
+          "declare every group while the module is loading",
+      );
+    }
+    const fullId = prefixWithGroup(parentGroupId, groupId);
+    this.#reserveNodeId(fullId, "Task group");
+    this.#groups.set(fullId, {
+      groupId: fullId,
+      ...(parentGroupId !== undefined && { parentGroupId }),

Review Comment:
   Group ids now follow `validate_group_key`: at most 200 characters, letters, 
digits, dashes and underscores only.



##########
ts-sdk/src/sdk/dag.ts:
##########
@@ -406,6 +508,25 @@ export class Dag {
     taskIdOrHandler: string | ((args: TArgs) => TReturn | Promise<TReturn>),
     handlerOrOptions?: ((args: TArgs) => TReturn | Promise<TReturn>) | 
TaskOptions,
     maybeOptions?: TaskOptions,
+  ): TaskFactory<TArgs, TReturn> {
+    return this.#addTask(undefined, taskIdOrHandler, handlerOrOptions, 
maybeOptions);
+  }
+
+  /**
+   * Declare a task group of this Dag.
+   *
+   * The group prefixes the id of every task declared in it, and stands at
+   * either end of an order-only edge in its own right.
+   */
+  taskGroup(groupId: string): TaskGroupRef {
+    return this.#addGroup(undefined, groupId);
+  }

Review Comment:
   Added `dag.taskGroup(id, { prefixGroupId: false })`, following Python: the 
group's tasks and nested groups keep the ids they are given, and the flag is 
serialized as `prefix_group_id` (#73441).



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