diff --git a/src/frontend/src/handler/create_sql_function.rs b/src/frontend/src/handler/create_sql_function.rs index 166e940b60810..4f3f7cfa0117b 100644 --- a/src/frontend/src/handler/create_sql_function.rs +++ b/src/frontend/src/handler/create_sql_function.rs @@ -29,7 +29,7 @@ use thiserror_ext::AsReport; use super::*; use crate::binder::UdfContext; use crate::catalog::CatalogError; -use crate::expr::{ExprImpl, Literal}; +use crate::expr::{Expr, ExprImpl, Literal}; use crate::{bind_data_type, Binder}; /// Create a mock `udf_context`, which is used for semantic check @@ -176,12 +176,27 @@ pub async fn handle_create_sql_function( .update_context(create_mock_udf_context(arg_types.clone())); if let Ok(expr) = UdfContext::extract_udf_expression(ast) { - if let Err(e) = binder.bind_expr(expr) { + let bind_result = binder.bind_expr(expr); + + if let Err(e) = &bind_result { return Err(ErrorCode::InvalidInputSyntax(format!( "failed to conduct semantic check, please see if you are calling non-existence functions: {}", e.as_report() )) .into()); + } else { + // We can safely unwrap here + let e = bind_result.unwrap(); + + // Check if the return type mismatches + if e.return_type() != return_type { + return Err(ErrorCode::InvalidInputSyntax(format!( + "return type mismatch detected\nexpected: {}\nactual: {}\nplease adjust your function definition accordingly", + return_type, + e.return_type() + )) + .into()); + } } } else { return Err(ErrorCode::InvalidInputSyntax(