leaves12138 commented on code in PR #1429:
URL: https://github.com/apache/paimon-rust/pull/1429#discussion_r4595840527
##########
crates/integrations/datafusion/src/sql_context.rs:
##########
@@ -5100,6 +5166,166 @@ 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
+ .err()
Review Comment:
[P2] Replace err().expect() to unblock the Clippy job
CI runs `cargo +1.98.0 clippy --locked --all-targets --workspace --features
vortex -- -D warnings`, so this newly added `.err().expect(...)` chain fails
with `clippy::err_expect`. The `check` job for this PR has already failed at
these lines; normal tests and formatting do not catch it. Replace the chain
with `.await.expect_err("temporary function drop must be rejected")` to
preserve the assertion while allowing the lint check to pass.
--
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]