JingsongLi commented on code in PR #939:
URL: https://github.com/apache/paimon-rust/pull/939#discussion_r4177880587


##########
crates/paimon/src/table/branch_manager.rs:
##########
@@ -143,10 +143,24 @@ impl BranchManager {
 
     /// Create a new branch by copying the latest schema to the branch 
directory.
     pub async fn create_branch(&self, branch_name: &str) -> crate::Result<()> {
+        self.create_branch_on_branch(branch_name, None).await
+    }
+
+    /// Like [`create_branch`](Self::create_branch), but reads the latest 
schema
+    /// from `source_branch` (`None` = the main branch). Branches are flat, so 
the
+    /// new branch is still created under the table root; only the schema 
source
+    /// is scoped. Lets `create_branch(table => 't$branch_b1', branch => 'b2')`
+    /// seed `b2` from `b1`'s schema instead of failing to resolve the base 
table.
+    pub async fn create_branch_on_branch(
+        &self,
+        branch_name: &str,
+        source_branch: Option<&str>,
+    ) -> crate::Result<()> {
         self.validate_branch(branch_name).await?;
-        let schema_manager = SchemaManager::new(self.file_io.clone(), 
self.table_path.clone());
-        if let Some(latest) = schema_manager.latest().await? {
-            self.copy_schemas_to_branch(branch_name, latest.id())
+        let source_branch = source_branch.filter(|b| *b != 
DEFAULT_MAIN_BRANCH);
+        let source_schema_manager = self.scoped_schema_manager(source_branch);
+        if let Some(latest) = source_schema_manager.latest().await? {

Review Comment:
   [P2] Reject a missing source branch before reporting success. After the new 
base-table resolution, `CALL sys.create_branch(table => 
'test_db.t1$branch_missing', branch => 'b2')` reaches this method even when 
`missing` has no schema. `latest()` returns None, the copy is skipped, and 
`Ok(())` makes CALL report success although b2 was never created. An actual 
local Parquet/SQL probe on this revision + main reproduces `CALL=Ok(())` and 
`branch_exists("b2")=false`; the same schema-only operation from a valid source 
succeeds. Java switchToBranch refuses a missing source, and 
FileSystemBranchManager.createBranch requires latestSchema. Please require the 
source schema (or validate source-branch existence) and error before reporting 
successful creation.



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