SteNicholas opened a new issue, #1340:
URL: https://github.com/apache/paimon-rust/issues/1340

   ### Search before asking
   
   - [x] I searched in the 
[issues](https://github.com/apache/paimon-rust/issues) and found nothing 
similar.
   
   ### Motivation
   
   `RESTCatalog` already implements branch creation and deletion through the 
REST API ([`create_branch` / 
`drop_branch`](https://github.com/apache/paimon-rust/blob/f1f0562904900584212ce42c0178ed1f9778b719/crates/paimon/src/catalog/rest/rest_catalog.rs#L532-L581),
 added in #1141). But the DataFusion SQL procedures still refuse every 
REST-managed table:
   
   - 
[`proc_create_branch`](https://github.com/apache/paimon-rust/blob/f1f0562904900584212ce42c0178ed1f9778b719/crates/integrations/datafusion/src/procedures.rs#L777-L781)
 returns `NotImplemented: create_branch is not supported for tables managed by 
a REST catalog`.
   - 
[`proc_delete_branch`](https://github.com/apache/paimon-rust/blob/f1f0562904900584212ce42c0178ed1f9778b719/crates/integrations/datafusion/src/procedures.rs#L853-L857)
 returns `NotImplemented: delete_branch is not yet supported ...`. Its comment 
says "the Rust REST catalog has no branch-drop endpoint yet", which is no 
longer true.
   
   So users of a REST catalog cannot run `CALL sys.create_branch(...)` or `CALL 
sys.delete_branch(...)` even though the catalog supports both. The refusal was 
the right call while no catalog-aware path existed (writing branch directories 
with `BranchManager` would bypass the catalog's metadata). That path now exists.
   
   ### Solution
   
   For tables with `rest_env()`, route the procedures through the `Catalog` 
trait instead of `BranchManager`. Non-REST tables keep the current filesystem 
path.
   
   **create_branch**
   - Keep the existing local checks (`validate_branch_name`, no `$` in the 
name, main-branch source table, not a format table).
   - Call `catalog.create_branch(&identifier, branch, tag)`.
   - `ignore_if_exists => true`: treat `Error::BranchAlreadyExist` as success, 
instead of probing the filesystem first.
   
   **delete_branch**
   - Keep the comma-split behavior, `validate_branch_name` and 
`ensure_branch_deletable` per name.
   - Call `catalog.drop_branch(&identifier, name)` for each name.
   - A missing branch is skipped today on the filesystem path; keep that by 
treating `Error::BranchNotExist` as a no-op.
   - Remove the stale comment.
   
   **Error mapping** (check `map_rest_error_for_branch` and the `create_branch` 
mapping)
   - 403 `Forbidden` / 401 `NotAuthorized` should surface as a clear permission 
error, not a generic one.
   - 404 on the table → `TableNotExist`; 404 on the tag → `TagNotExist`; 409 → 
`BranchAlreadyExist`.
   - Today `drop_branch` maps every `NoSuchResource` to `BranchNotExist`, so a 
missing table would be silently skipped by the rule above. It should only map 
to `BranchNotExist` when the resource type is `BRANCH` (or unset), and to 
`TableNotExist` for `TABLE`.
   
   **Tests** 
(`crates/integrations/datafusion/tests/rest_management_procedures.rs`)
   - Create a branch (empty and from tag), then confirm `list_branches` shows 
it.
   - Create twice: error without `ignore_if_exists`, success with it.
   - Create from a missing tag → tag-not-exist error.
   - Delete an existing branch; delete a missing branch is a no-op; delete 
several comma-separated names.
   - Permission denied (403) on create and delete → permission error, and no 
local files are touched.
   - Replace `test_create_branch_rejects_rest_tables_even_when_target_exists`, 
which asserts the old refusal.
   
   ### Anything else?
   
   Suggested split into two small PRs: create_branch first, then delete_branch.
   
   `rename_branch` is out of scope: Java `RESTCatalog.renameBranch` is 
unsupported and there is no REST endpoint for it, so the refusal stays.
   
   ### Willingness to contribute
   
   - [ ] I'm willing to submit a PR!
   


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