This is an automated email from the ASF dual-hosted git repository.

JingsongLi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/paimon-rust.git


The following commit(s) were added to refs/heads/main by this push:
     new 907fb9b0 [core][datafusion] Support persistent DROP FUNCTION (#1429)
907fb9b0 is described below

commit 907fb9b06854560606e15ca3ee0aad8a0797f899
Author: Jingsong Lee <[email protected]>
AuthorDate: Tue Nov 17 14:10:55 2026 +0800

    [core][datafusion] Support persistent DROP FUNCTION (#1429)
---
 crates/integrations/datafusion/README.md          |  10 +-
 crates/integrations/datafusion/src/sql_context.rs | 225 ++++++++++++++++++++++
 crates/paimon/src/api/rest_api.rs                 |  11 +-
 crates/paimon/src/catalog/mod.rs                  |  15 ++
 crates/paimon/src/catalog/rest/rest_catalog.rs    |  15 ++
 crates/paimon/tests/mock_server.rs                |  41 +++-
 crates/paimon/tests/rest_api_test.rs              |  49 +++++
 crates/paimon/tests/rest_catalog_test.rs          |  70 +++++++
 docs/src/sql.md                                   |  25 ++-
 9 files changed, 452 insertions(+), 9 deletions(-)

diff --git a/crates/integrations/datafusion/README.md 
b/crates/integrations/datafusion/README.md
index 20e53b13..181e6e38 100644
--- a/crates/integrations/datafusion/README.md
+++ b/crates/integrations/datafusion/README.md
@@ -77,7 +77,7 @@ allocation overhead are not fully accounted, so the pool is 
not an RSS limit.
 
 ## REST Catalog views and SQL functions
 
-`SQLContext` can read, execute, create, and drop persistent views and can 
create SQL scalar functions in a Paimon REST Catalog:
+`SQLContext` can read, execute, create, and drop persistent views and SQL 
scalar functions in a Paimon REST Catalog:
 
 ```sql
 CREATE VIEW [IF NOT EXISTS] view_name [(column_name, ...)] AS query;
@@ -87,6 +87,8 @@ CREATE FUNCTION [IF NOT EXISTS] function_name([parameter_name 
data_type, ...])
 RETURNS data_type
 [LANGUAGE SQL]
 RETURN scalar_expression;
+
+DROP FUNCTION [IF EXISTS] function_name;
 ```
 
 - A persistent view is resolved lazily like a table. The `datafusion` dialect 
is preferred and the
@@ -109,8 +111,12 @@ RETURN scalar_expression;
   inferred and validated from the planned expression before sending the REST 
create request. Bare,
   two-part, and three-part creation targets are supported; calls remain 
limited to bare and
   three-part names.
+- Persistent `DROP FUNCTION` accepts bare, two-part, and three-part names and 
sends one direct
+  REST delete request. `IF EXISTS` ignores only a missing function. Multiple 
targets, argument
+  signatures, `CASCADE`, `RESTRICT`, and `DROP TEMPORARY FUNCTION` are not 
supported for Paimon catalogs.
+  Catalogs without persistent function support may return `Unsupported`.
 - `CREATE OR REPLACE VIEW`, materialized/secure views, comments/options, 
persistent `ALTER VIEW`,
-  `CREATE OR REPLACE/ALTER/TEMPORARY FUNCTION`, and persistent `ALTER 
FUNCTION` / `DROP FUNCTION`
+  `CREATE OR REPLACE/ALTER/TEMPORARY FUNCTION`, and persistent `ALTER FUNCTION`
   are not supported. Lambda/file, aggregate/table/multi-return, 
non-deterministic, Stable/Volatile,
   and non-SQL functions are also not supported.
 
diff --git a/crates/integrations/datafusion/src/sql_context.rs 
b/crates/integrations/datafusion/src/sql_context.rs
index 65c7cbcb..1e515d29 100644
--- a/crates/integrations/datafusion/src/sql_context.rs
+++ b/crates/integrations/datafusion/src/sql_context.rs
@@ -41,6 +41,7 @@
 //! - `CREATE VIEW [IF NOT EXISTS] view [(col, ...)] AS query`
 //! - `DROP VIEW [IF EXISTS] view`
 //! - `CREATE FUNCTION name(args) RETURNS type [LANGUAGE SQL] RETURN 
expression`
+//! - `DROP FUNCTION [IF EXISTS] name`
 //! - `TRUNCATE TABLE db.t`
 //! - `TRUNCATE TABLE db.t PARTITION (col = val, ...)`
 
@@ -741,6 +742,49 @@ impl SQLContext {
                     self.ctx.sql_with_options(sql, options).await
                 }
             }
+            Statement::DropFunction(drop_function)
+                if drop_function
+                    .func_desc
+                    .iter()
+                    .any(|function| 
self.is_paimon_function_name(&function.name)) =>
+            {
+                // sqlparser consumes TEMPORARY without retaining it in the 
function AST.
+                let temporary = {
+                    let mut parser = Parser::new(&GenericDialect {})
+                        .try_with_sql(&rewritten_sql)
+                        .map_err(|error| {
+                            DataFusionError::Plan(format!("SQL parse error: 
{error}"))
+                        })?;
+                    while parser.consume_token(&Token::SemiColon) {}
+                    parser.parse_keywords(&[Keyword::DROP, Keyword::TEMPORARY, 
Keyword::FUNCTION])
+                };
+                if temporary {
+                    return Err(DataFusionError::NotImplemented(
+                        "DROP TEMPORARY FUNCTION is not supported for Paimon 
catalogs".to_string(),
+                    ));
+                }
+                let [function] = drop_function.func_desc.as_slice() else {
+                    return Err(DataFusionError::Plan(
+                        "Persistent DROP FUNCTION does not support multiple 
functions".to_string(),
+                    ));
+                };
+                if let Some(behavior) = &drop_function.drop_behavior {
+                    return Err(DataFusionError::Plan(format!(
+                        "DROP FUNCTION {behavior} is not supported"
+                    )));
+                }
+                if function.args.is_some() {
+                    return Err(DataFusionError::Plan(
+                        "DROP FUNCTION argument signatures are not 
supported".to_string(),
+                    ));
+                }
+                let (catalog, _, identifier) = 
self.resolve_catalog_and_function(&function.name)?;
+                catalog
+                    .drop_function(&identifier, drop_function.if_exists)
+                    .await
+                    .map_err(to_datafusion_error)?;
+                ok_result(&self.ctx)
+            }
             Statement::Drop {
                 object_type: ObjectType::Database,
                 if_exists,
@@ -4387,6 +4431,14 @@ mod tests {
     };
     use paimon::table::Table;
 
+    #[test]
+    fn test_sql_context_sql_future_is_send() {
+        fn assert_send(_: impl Send) {}
+        let ctx = SQLContext::new();
+        assert_send(ctx.sql("DROP FUNCTION db.fn"));
+        assert_send(ctx.sql_with_options("DROP FUNCTION db.fn", 
SQLOptions::new()));
+    }
+
     #[test]
     fn test_sql_context_builder_uses_custom_runtime_env() {
         let runtime_env = RuntimeEnvBuilder::new()
@@ -4584,6 +4636,20 @@ mod tests {
             Ok(())
         }
 
+        async fn drop_function(
+            &self,
+            identifier: &Identifier,
+            ignore_if_not_exists: bool,
+        ) -> paimon::Result<()> {
+            if self.functions.lock().unwrap().remove(identifier).is_some() || 
ignore_if_not_exists {
+                Ok(())
+            } else {
+                Err(paimon::Error::FunctionNotExist {
+                    full_name: identifier.full_name(),
+                })
+            }
+        }
+
         async fn get_function(
             &self,
             identifier: &Identifier,
@@ -5100,6 +5166,165 @@ mod tests {
         assert_eq!(answers.value(0), 42);
     }
 
+    #[tokio::test]
+    async fn 
persistent_rest_catalog_function_drop_resolves_supported_name_forms() {
+        let catalog = Arc::new(MockCatalog::new());
+        let other_catalog = Arc::new(MockCatalog::new());
+        let mut ctx = make_sql_context(Arc::clone(&catalog)).await;
+        ctx.register_catalog("other", other_catalog.clone())
+            .await
+            .unwrap();
+        ctx.set_current_database("session_db").await.unwrap();
+        for (sql, target, database, name) in [
+            ("DROP FUNCTION BARE", &catalog, "session_db", "bare"),
+            (
+                "DROP FUNCTION IF EXISTS DB.QUALIFIED",
+                &catalog,
+                "db",
+                "qualified",
+            ),
+            ("DROP FUNCTION OTHER.DB.FULL", &other_catalog, "db", "full"),
+            (
+                "DROP FUNCTION \"other\".\"Db\".\"Fn\"",
+                &other_catalog,
+                "Db",
+                "Fn",
+            ),
+            ("DROP FUNCTION \"Db\".\"Fn\"", &catalog, "Db", "Fn"),
+            (
+                "DROP FUNCTION \"TEMPORARY\"",
+                &catalog,
+                "session_db",
+                "TEMPORARY",
+            ),
+            (
+                "; /* empty */ ; DROP FUNCTION db.\"quoted.fn\";",
+                &catalog,
+                "db",
+                "quoted.fn",
+            ),
+        ] {
+            add_unary_sql_function_in_database(target, database, name, "x + 
1", true);
+            ctx.sql(sql).await.unwrap();
+            assert!(target.function_lookups.lock().unwrap().is_empty());
+            assert!(matches!(
+                target.get_function(&Identifier::new(database, name)).await,
+                Err(paimon::Error::FunctionNotExist { .. })
+            ));
+            target.function_lookups.lock().unwrap().clear();
+        }
+    }
+
+    #[tokio::test]
+    async fn persistent_rest_catalog_function_drop_honors_if_exists() {
+        let catalog = Arc::new(MockCatalog::new());
+        let ctx = make_sql_context(catalog).await;
+
+        let error = ctx.sql("DROP FUNCTION db.missing").await.unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("Function db.missing does not exist"),
+            "{error}"
+        );
+        ctx.sql("DROP FUNCTION IF EXISTS db.missing").await.unwrap();
+    }
+
+    #[tokio::test]
+    async fn 
persistent_rest_catalog_function_drop_rejects_unsupported_forms_before_deleting()
 {
+        let catalog = Arc::new(MockCatalog::new());
+        add_unary_sql_function(&catalog, "kept", "x + 1", true);
+        let ctx = make_sql_context(Arc::clone(&catalog)).await;
+        for (sql, expected) in [
+            ("DROP FUNCTION kept CASCADE", "CASCADE"),
+            ("DROP FUNCTION kept RESTRICT", "RESTRICT"),
+            ("DROP FUNCTION kept()", "signatures"),
+            ("DROP FUNCTION kept(BIGINT)", "signatures"),
+            ("DROP FUNCTION kept; SELECT 1", "exactly one SQL statement"),
+            (
+                "DROP FUNCTION datafusion.public.other, paimon.default.kept",
+                "multiple functions",
+            ),
+        ] {
+            let error = ctx.sql(sql).await.unwrap_err();
+            assert!(error.to_string().contains(expected), "{sql}: {error}");
+            assert!(catalog
+                .functions
+                .lock()
+                .unwrap()
+                .contains_key(&Identifier::new("default", "kept")));
+        }
+    }
+
+    #[tokio::test]
+    async fn 
persistent_rest_catalog_function_drop_preserves_local_function_with_same_name() 
{
+        let catalog = Arc::new(MockCatalog::new());
+        add_unary_sql_function(&catalog, "abs", "x + 1", true);
+        let ctx = make_sql_context(Arc::clone(&catalog)).await;
+        ctx.sql("DROP FUNCTION abs").await.unwrap();
+        assert!(catalog.functions.lock().unwrap().is_empty());
+        ctx.sql("DROP FUNCTION IF EXISTS abs").await.unwrap();
+        assert!(ctx.ctx.state().scalar_functions().contains_key("abs"));
+        ctx.sql("SELECT abs(-1)")
+            .await
+            .unwrap()
+            .collect()
+            .await
+            .unwrap();
+    }
+
+    #[tokio::test]
+    async fn 
persistent_rest_catalog_function_drop_rejects_temporary_before_deleting() {
+        let catalog = Arc::new(MockCatalog::new());
+        add_unary_sql_function(&catalog, "abs", "x + 1", true);
+        add_unary_sql_function_in_database(&catalog, "db", "kept", "x + 1", 
true);
+        let ctx = make_sql_context(Arc::clone(&catalog)).await;
+        for sql in [
+            "DROP TEMPORARY FUNCTION abs",
+            "-- leading comment\nDROP /* modifier */ TEMPORARY FUNCTION IF 
EXISTS db.kept",
+            "; /* empty statements */ ; dRoP TeMpOrArY FuNcTiOn IF EXISTS 
db.kept;",
+        ] {
+            let error = ctx
+                .sql(sql)
+                .await
+                .expect_err("temporary function drop must be rejected");
+            assert!(
+                error.to_string().contains("DROP TEMPORARY FUNCTION"),
+                "{error}"
+            );
+            assert_eq!(catalog.functions.lock().unwrap().len(), 2);
+            assert!(ctx.ctx.state().scalar_functions().contains_key("abs"));
+        }
+    }
+
+    #[tokio::test]
+    async fn function_drop_delegates_without_paimon_catalog() {
+        for sql in ["DROP FUNCTION abs", "DROP TEMPORARY FUNCTION abs"] {
+            let ctx = SQLContext::new();
+            assert!(ctx.ctx.state().scalar_functions().contains_key("abs"));
+            ctx.sql(sql).await.unwrap();
+            assert!(!ctx.ctx.state().scalar_functions().contains_key("abs"));
+        }
+    }
+
+    #[tokio::test]
+    async fn 
persistent_rest_catalog_function_drop_preserves_unsupported_catalog_error() {
+        let mut ctx = SQLContext::new();
+        ctx.register_catalog_with_default_db("paimon", 
Arc::new(ProbeTrackingCatalog::new()), None)
+            .await
+            .unwrap();
+        let error = ctx
+            .sql("DROP FUNCTION IF EXISTS db.missing")
+            .await
+            .unwrap_err();
+        assert!(
+            error
+                .to_string()
+                .contains("Catalog does not support functions"),
+            "{error}"
+        );
+    }
+
     #[tokio::test]
     async fn 
persistent_rest_catalog_function_uses_databricks_default_sql_syntax() {
         let catalog = Arc::new(MockCatalog::new());
diff --git a/crates/paimon/src/api/rest_api.rs 
b/crates/paimon/src/api/rest_api.rs
index 8752fe0d..86a51a28 100644
--- a/crates/paimon/src/api/rest_api.rs
+++ b/crates/paimon/src/api/rest_api.rs
@@ -82,7 +82,7 @@ fn validate_non_empty_multi(values: &[(&str, &str)]) -> 
Result<()> {
 }
 
 /// `url` normalizes dot segments even when their dots are percent encoded.
-/// Reject them before a branch mutation can be redirected to a parent 
resource.
+/// Reject them before a metadata request can be redirected to a parent 
resource.
 fn validate_resource_path(values: &[(&str, &str)]) -> Result<()> {
     validate_non_empty_multi(values)?;
     for (value, field_name) in values {
@@ -674,6 +674,15 @@ impl RESTApi {
         self.client.get(&path, None::<&[(&str, &str)]>).await
     }
 
+    /// Drop a persistent function.
+    pub async fn drop_function(&self, identifier: &Identifier) -> Result<()> {
+        let database = identifier.database();
+        let function = identifier.object();
+        validate_resource_path(&[(database, "database name"), (function, 
"function name")])?;
+        let path = self.resource_paths.function(database, function);
+        self.client.delete_without_response(&path).await
+    }
+
     // ==================== Partition Operations ====================
 
     /// Create table partitions in a single REST request.
diff --git a/crates/paimon/src/catalog/mod.rs b/crates/paimon/src/catalog/mod.rs
index 3cf2cf97..72c936e3 100644
--- a/crates/paimon/src/catalog/mod.rs
+++ b/crates/paimon/src/catalog/mod.rs
@@ -700,6 +700,21 @@ pub trait Catalog: Send + Sync {
         })
     }
 
+    /// Drop a persistent function.
+    ///
+    /// # Errors
+    /// * [`crate::Error::FunctionNotExist`] - function does not exist when
+    ///   `ignore_if_not_exists` is false.
+    async fn drop_function(
+        &self,
+        _identifier: &Identifier,
+        _ignore_if_not_exists: bool,
+    ) -> Result<()> {
+        Err(Error::Unsupported {
+            message: "Catalog does not support functions".to_string(),
+        })
+    }
+
     /// List persistent function names in a database.
     async fn list_functions(&self, _database_name: &str) -> 
Result<Vec<String>> {
         Err(Error::Unsupported {
diff --git a/crates/paimon/src/catalog/rest/rest_catalog.rs 
b/crates/paimon/src/catalog/rest/rest_catalog.rs
index 81bb5c09..018e2ba2 100644
--- a/crates/paimon/src/catalog/rest/rest_catalog.rs
+++ b/crates/paimon/src/catalog/rest/rest_catalog.rs
@@ -642,6 +642,21 @@ impl Catalog for RESTCatalog {
         })
     }
 
+    async fn drop_function(
+        &self,
+        identifier: &Identifier,
+        ignore_if_not_exists: bool,
+    ) -> Result<()> {
+        let result = self
+            .api
+            .drop_function(identifier)
+            .await
+            .map_err(|error| map_rest_error_for_function(error, identifier));
+        ignore_error_if(result, |error| {
+            ignore_if_not_exists && matches!(error, Error::FunctionNotExist { 
.. })
+        })
+    }
+
     async fn get_function(&self, identifier: &Identifier) -> 
Result<crate::catalog::Function> {
         let response = self
             .api
diff --git a/crates/paimon/tests/mock_server.rs 
b/crates/paimon/tests/mock_server.rs
index f13a8833..345c545d 100644
--- a/crates/paimon/tests/mock_server.rs
+++ b/crates/paimon/tests/mock_server.rs
@@ -94,6 +94,7 @@ struct MockState {
     list_partitions_by_filter_error_status: Option<StatusCode>,
     view_function_endpoints_unsupported: bool,
     drop_view_error_status: Option<StatusCode>,
+    drop_function_error_status: Option<StatusCode>,
     list_page_size: Option<usize>,
     no_permission_databases: HashSet<String>,
     no_permission_tables: HashSet<String>,
@@ -655,6 +656,39 @@ impl RESTServer {
         }
     }
 
+    /// Handle DELETE /databases/:db/functions/:function - drop a persistent 
function.
+    pub async fn drop_function(
+        Path((db, function)): Path<(String, String)>,
+        Extension(state): Extension<Arc<RESTServer>>,
+    ) -> impl IntoResponse {
+        let mut s = state.inner.lock().unwrap();
+        let status = if s.view_function_endpoints_unsupported {
+            Some(StatusCode::NOT_IMPLEMENTED)
+        } else {
+            s.drop_function_error_status
+        };
+        if let Some(status) = status {
+            let err = ErrorResponse::new(
+                Some("function".to_string()),
+                Some(function),
+                status.canonical_reason().map(ToString::to_string),
+                Some(status.as_u16() as i32),
+            );
+            return (status, Json(err)).into_response();
+        }
+        if s.functions.remove(&format!("{db}.{function}")).is_some() {
+            StatusCode::NO_CONTENT.into_response()
+        } else {
+            let err = ErrorResponse::new(
+                Some("function".to_string()),
+                Some(function),
+                Some("Not Found".to_string()),
+                Some(404),
+            );
+            (StatusCode::NOT_FOUND, Json(err)).into_response()
+        }
+    }
+
     /// Handle GET /databases/:db/functions - list persistent functions.
     pub async fn list_functions(
         Path(db): Path<String>,
@@ -2193,6 +2227,11 @@ impl RESTServer {
         self.inner.lock().unwrap().drop_view_error_status = status;
     }
 
+    /// Make the drop-function endpoint return the given status.
+    pub fn set_drop_function_error_status(&self, status: Option<StatusCode>) {
+        self.inner.lock().unwrap().drop_function_error_status = status;
+    }
+
     /// Make the create-partitions endpoint return the given status.
     pub fn set_create_partitions_error_status(&self, status: 
Option<StatusCode>) {
         self.inner.lock().unwrap().create_partitions_error_status = status;
@@ -2862,7 +2901,7 @@ pub async fn start_mock_server(
         )
         .route(
             &format!("{prefix}/databases/:db/functions/:function"),
-            get(RESTServer::get_function),
+            get(RESTServer::get_function).delete(RESTServer::drop_function),
         )
         .route(
             &format!("{prefix}/databases/:db/tables/:table/auth"),
diff --git a/crates/paimon/tests/rest_api_test.rs 
b/crates/paimon/tests/rest_api_test.rs
index 1649b5a2..8699d31b 100644
--- a/crates/paimon/tests/rest_api_test.rs
+++ b/crates/paimon/tests/rest_api_test.rs
@@ -341,6 +341,55 @@ async fn test_create_function() {
     assert_eq!(response.input_params.unwrap()[0].name(), "x");
 }
 
+#[tokio::test]
+async fn test_drop_function_uses_encoded_individual_function_path() {
+    let ctx = setup_test_server(vec!["db+%"]).await;
+    let function = Function::new(
+        Identifier::new("db+%", "fn+?#%"),
+        None,
+        None,
+        true,
+        HashMap::new(),
+        None,
+        HashMap::new(),
+    );
+    ctx.api.create_function(&function).await.unwrap();
+
+    ctx.api.drop_function(function.identifier()).await.unwrap();
+
+    assert!(ctx.api.list_functions("db+%").await.unwrap().is_empty());
+    assert!(matches!(
+        ctx.api
+            .drop_function(function.identifier())
+            .await
+            .unwrap_err(),
+        paimon::Error::RestApi {
+            source: RestError::NoSuchResource { .. }
+        }
+    ));
+}
+
+#[tokio::test]
+async fn test_drop_function_rejects_dot_path_segments() {
+    let ctx = setup_test_server(vec!["default"]).await;
+    for (database, function) in [
+        (".", "fn"),
+        ("..", "fn"),
+        ("default", "."),
+        ("default", ".."),
+    ] {
+        let error = ctx
+            .api
+            .drop_function(&Identifier::new(database, function))
+            .await
+            .unwrap_err();
+        assert!(
+            matches!(error, paimon::Error::ConfigInvalid { message } if 
message.contains("dot path segment"))
+        );
+    }
+    assert_eq!(ctx.api.list_databases().await.unwrap(), vec!["default"]);
+}
+
 #[tokio::test]
 async fn test_create_database() {
     let ctx = setup_test_server(vec!["default"]).await;
diff --git a/crates/paimon/tests/rest_catalog_test.rs 
b/crates/paimon/tests/rest_catalog_test.rs
index 7f79263c..3be7e745 100644
--- a/crates/paimon/tests/rest_catalog_test.rs
+++ b/crates/paimon/tests/rest_catalog_test.rs
@@ -2531,6 +2531,76 @@ async fn test_catalog_create_function() {
     assert_eq!(stored, function);
 }
 
+#[tokio::test]
+async fn test_catalog_drop_function() {
+    let ctx = setup_catalog(vec!["default"]).await;
+    let identifier = Identifier::new("default", "answer");
+    let function = Function::new(
+        identifier.clone(),
+        None,
+        None,
+        true,
+        HashMap::new(),
+        None,
+        HashMap::new(),
+    );
+    ctx.catalog.create_function(&function, false).await.unwrap();
+
+    ctx.catalog.drop_function(&identifier, false).await.unwrap();
+
+    assert!(ctx
+        .catalog
+        .list_functions("default")
+        .await
+        .unwrap()
+        .is_empty());
+    assert!(matches!(
+        ctx.catalog.get_function(&identifier).await.unwrap_err(),
+        paimon::Error::FunctionNotExist { full_name } if full_name == 
"default.answer"
+    ));
+    assert!(matches!(
+        ctx.catalog.drop_function(&identifier, false).await.unwrap_err(),
+        paimon::Error::FunctionNotExist { full_name } if full_name == 
"default.answer"
+    ));
+    ctx.catalog.drop_function(&identifier, true).await.unwrap();
+}
+
+#[tokio::test]
+async fn test_catalog_drop_function_if_exists_preserves_other_errors() {
+    let ctx = setup_catalog(vec!["default"]).await;
+    let identifier = Identifier::new("default", "answer");
+    for status in [
+        StatusCode::FORBIDDEN,
+        StatusCode::INTERNAL_SERVER_ERROR,
+        StatusCode::NOT_IMPLEMENTED,
+    ] {
+        ctx.server.set_drop_function_error_status(Some(status));
+        let error = ctx
+            .catalog
+            .drop_function(&identifier, true)
+            .await
+            .unwrap_err();
+        match status {
+            StatusCode::FORBIDDEN => assert!(matches!(
+                error,
+                paimon::Error::RestApi {
+                    source: paimon::api::RestError::Forbidden { .. }
+                }
+            )),
+            StatusCode::INTERNAL_SERVER_ERROR => assert!(matches!(
+                error,
+                paimon::Error::RestApi {
+                    source: paimon::api::RestError::ServiceFailure { .. }
+                }
+            )),
+            StatusCode::NOT_IMPLEMENTED => {
+                assert!(matches!(error, paimon::Error::Unsupported { .. }))
+            }
+            _ => unreachable!(),
+        }
+    }
+}
+
 #[tokio::test]
 async fn test_catalog_create_function_already_exists() {
     let ctx = setup_catalog(vec!["default"]).await;
diff --git a/docs/src/sql.md b/docs/src/sql.md
index 0122c958..dd846371 100644
--- a/docs/src/sql.md
+++ b/docs/src/sql.md
@@ -41,7 +41,7 @@ and writes to ordinary Paimon tables can create them with 
`file.format=mosaic`.
 SQL support has two layers:
 
 - DataFusion provides the parser, query planner, optimizer, execution engine, 
expressions, scalar functions, aggregate functions, and window functions. SQL 
statements that `SQLContext` does not intercept are delegated to DataFusion. 
This includes the DataFusion SQL surface for `SELECT` queries, CTEs (including 
recursive CTEs), subqueries, joins including `LATERAL` joins, SQL lambda 
functions, grouping, `HAVING`, window clauses, `QUALIFY`, set operations, 
`ORDER BY`, `LIMIT`/`OFFSET`, `EX [...]
-- Paimon-specific table management and row-level writes are implemented by 
`SQLContext`. This includes Paimon `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`, 
`CREATE TEMPORARY TABLE`, `CREATE TEMPORARY VIEW`, REST Catalog persistent 
`CREATE VIEW`, `DROP VIEW`, and `CREATE FUNCTION`, `DROP TEMPORARY TABLE` / 
`VIEW`, `INSERT OVERWRITE ... PARTITION`, `UPDATE`, `DELETE`, `TRUNCATE TABLE`, 
`ALTER TABLE ... ADD PARTITION`, `ALTER TABLE ... DROP PARTITION`, `SHOW 
PARTITIONS`, `MSCK REPAIR TABLE`, [...]
+- Paimon-specific table management and row-level writes are implemented by 
`SQLContext`. This includes Paimon `CREATE TABLE`, `ALTER TABLE`, `DROP TABLE`, 
`CREATE TEMPORARY TABLE`, `CREATE TEMPORARY VIEW`, REST Catalog persistent 
`CREATE VIEW`, `DROP VIEW`, `CREATE FUNCTION`, and `DROP FUNCTION`, `DROP 
TEMPORARY TABLE` / `VIEW`, `INSERT OVERWRITE ... PARTITION`, `UPDATE`, 
`DELETE`, `TRUNCATE TABLE`, `ALTER TABLE ... ADD PARTITION`, `ALTER TABLE ... 
DROP PARTITION`, `SHOW PARTITIONS`, `MS [...]
 
 Not every DataFusion DDL/DML statement maps to a Paimon table operation. For 
Paimon catalogs, `CREATE EXTERNAL TABLE`, `LOCATION`, `CREATE MATERIALIZED 
VIEW`, and persistent `CREATE TABLE AS SELECT` are rejected or not implemented. 
Persistent `CREATE FUNCTION` is supported only for the REST Catalog SQL scalar 
form documented below. DataFusion `COPY` can export query results to files; it 
does not create or commit Paimon table files.
 
@@ -134,7 +134,7 @@ It also manages session-scoped dynamic options internally 
for `SET`/`RESET` supp
 
 ### REST Catalog Views and SQL Functions
 
-When the registered catalog is a Paimon REST Catalog, `SQLContext` can read, 
execute, create, and drop persistent views and can create SQL scalar functions.
+When the registered catalog is a Paimon REST Catalog, `SQLContext` can read, 
execute, create, and drop persistent views and SQL scalar functions.
 
 Create a persistent view with this syntax:
 
@@ -222,6 +222,21 @@ RETURN amount * DECIMAL '1.10';
 SELECT add_tax(total) FROM orders;
 ```
 
+Drop a persistent function using a bare, two-part, or three-part name:
+
+```sql
+DROP FUNCTION add_tax;
+DROP FUNCTION IF EXISTS reporting.add_tax;
+DROP FUNCTION IF EXISTS paimon.reporting.add_tax;
+```
+
+Persistent `DROP FUNCTION` is implemented by REST Catalog and sends a direct
+delete request. `IF EXISTS` ignores only a missing function; permission and
+server errors are preserved. Only one function may be dropped per statement.
+Argument signatures, `CASCADE`, `RESTRICT`, and `DROP TEMPORARY FUNCTION` are 
not
+supported for Paimon catalogs. Catalogs without persistent function support may
+return `Unsupported`.
+
 Bare, two-part (`database.function`), and three-part
 (`catalog.database.function`) names are accepted as creation targets. Unquoted
 names are normalized and quoted names are preserved. Calls remain limited to
@@ -275,9 +290,9 @@ functions. Two-part function names such as 
`database.function(...)`, lambda or
 file definitions, aggregate/table/multi-return functions, and non-deterministic
 functions are not supported. `CREATE OR REPLACE/ALTER/TEMPORARY FUNCTION`,
 non-SQL bodies, `STABLE`/`VOLATILE`, null-input/parallel/security/SET clauses,
-options/remote functions, and persistent `ALTER FUNCTION` / `DROP FUNCTION`
-are also not supported. Catalog implementations other than REST Catalog may
-return `Unsupported` for persistent function creation.
+options/remote functions, and persistent `ALTER FUNCTION` are also not 
supported.
+Catalog implementations other than REST Catalog may return `Unsupported` for
+persistent function creation or deletion.
 
 ## Data Types
 

Reply via email to