Skip to content

Commit

Permalink
add type mismatch check
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Jan 29, 2024
1 parent 8919044 commit 60fc4f3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/frontend/src/handler/create_sql_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 60fc4f3

Please sign in to comment.