dongjoon-hyun commented on code in PR #56102:
URL: https://github.com/apache/spark/pull/56102#discussion_r3300720036


##########
sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/SupportsBranching.java:
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.
+ */
+
+package org.apache.spark.sql.connector.catalog;
+
+import java.util.NoSuchElementException;
+import java.util.OptionalLong;
+
+import org.apache.spark.annotation.Evolving;
+
+/**
+ * A mix-in interface for {@link Table} branching support. Data sources can 
implement this
+ * interface to expose multi-branch capabilities (such as Iceberg branches) 
through standard
+ * Spark SQL DDL:
+ *
+ * <pre>
+ *   ALTER TABLE t CREATE [OR REPLACE] BRANCH [IF NOT EXISTS] name [AS OF 
VERSION snapshotId]
+ *   ALTER TABLE t DROP BRANCH [IF EXISTS] name
+ *   ALTER TABLE t FAST FORWARD branch TO target
+ *   SHOW BRANCHES IN t
+ * </pre>
+ *
+ * <p>The meaning of {@code snapshotId} is left to the data source. When a 
snapshot id is not
+ * supplied the implementation should branch from the current snapshot of the 
table.
+ *
+ * @since 4.3.0
+ */
+@Evolving
+public interface SupportsBranching extends Table {
+
+  /**
+   * Create a new branch on this table.
+   *
+   * @param name the branch name; must not be {@code null}
+   * @param sourceSnapshotId an optional snapshot id to branch from. If empty, 
the branch is
+   *                         created from the table's current snapshot.
+   * @return a {@link TableBranch} describing the new branch
+   * @throws BranchAlreadyExistsException if a branch with the given name 
already exists
+   * @throws NoSuchElementException if the requested {@code sourceSnapshotId} 
does not exist
+   */
+  TableBranch createBranch(String name, OptionalLong sourceSnapshotId);
+
+  /**
+   * Replace an existing branch (or create it if missing).
+   *
+   * <p>The default implementation drops the branch (if present) and then 
creates it again.
+   * Implementations may override this to perform the replacement atomically.
+   */
+  default TableBranch replaceBranch(String name, OptionalLong 
sourceSnapshotId) {
+    dropBranch(name);
+    return createBranch(name, sourceSnapshotId);
+  }
+
+  /**
+   * Drop the named branch.
+   *
+   * @return {@code true} if the branch was removed; {@code false} if it did 
not exist.
+   */
+  boolean dropBranch(String name);
+
+  /**
+   * Fast-forward {@code branch} to the head of {@code targetBranch}.
+   *
+   * <p>The operation succeeds only when the branch's current snapshot is an 
ancestor of the
+   * target branch's current snapshot. Implementations should throw
+   * {@link IllegalArgumentException} otherwise.
+   *
+   * @return the updated {@link TableBranch} after fast-forwarding
+   * @throws NoSuchElementException if either branch is missing
+   * @throws IllegalArgumentException if the operation would not be a 
fast-forward
+   */
+  TableBranch fastForward(String branch, String targetBranch);
+
+  /**
+   * List all branches of this table. The default implementation returns an 
empty array.
+   */
+  default TableBranch[] listBranches() {
+    return new TableBranch[0];
+  }
+
+  /**
+   * Thrown when a branch with the requested name already exists.
+   */
+  class BranchAlreadyExistsException extends RuntimeException {

Review Comment:
   What about something like `BranchNotFound` or `InvalidFastForward`?



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to