diff --git a/src/query/functions/src/scalars/geometry.rs b/src/query/functions/src/scalars/geometry.rs index 13b14f4266bc6..d668065c2c21e 100644 --- a/src/query/functions/src/scalars/geometry.rs +++ b/src/query/functions/src/scalars/geometry.rs @@ -86,8 +86,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError(e.to_string()).to_string(), ); - builder.commit_row(); - return; } }; builder.commit_row(); @@ -119,7 +117,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError(e.to_string()).to_string(), ); - builder.put_str(""); builder.commit_row(); return; } @@ -147,8 +144,13 @@ pub fn register(registry: &mut FunctionRegistry) { } } if geohash.len() > 12 { - ctx.set_error(builder.len(), ""); - builder.put_str("Currently the precision only implement within 12 digits!"); + ctx.set_error( + builder.len(), + ErrorCode::GeometryError( + "Currently the precision only implement within 12 digits!".to_string(), + ) + .to_string(), + ); builder.commit_row(); return; } @@ -160,7 +162,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError(e.to_string()).to_string(), ); - builder.put_str(""); builder.commit_row(); return; } @@ -218,7 +219,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError(e.to_string()).to_string(), ); - builder.put_str(""); builder.commit_row(); return; } @@ -278,7 +278,6 @@ pub fn register(registry: &mut FunctionRegistry) { }, Err(e) => { ctx.set_error(builder.len(), ErrorCode::GeometryError(e).to_string()); - builder.put_str(""); builder.commit_row(); return; } @@ -286,7 +285,6 @@ pub fn register(registry: &mut FunctionRegistry) { }, Err(e) => { ctx.set_error(builder.len(), ErrorCode::GeometryError(e.to_string()).to_string()); - builder.put_str(""); builder.commit_row(); return; } @@ -301,7 +299,6 @@ pub fn register(registry: &mut FunctionRegistry) { Ok(point) => point, Err(e) => { ctx.set_error(builder.len(), ErrorCode::GeometryError(e.to_string()).to_string()); - builder.put_str(""); builder.commit_row(); return; } @@ -312,8 +309,7 @@ pub fn register(registry: &mut FunctionRegistry) { let line: LineString = match g.try_into() { Ok(line) => line, Err(e) => { - ctx.set_error(builder.len(), e.to_string()); - builder.put_str(""); + ctx.set_error(builder.len(), ErrorCode::GeometryError(e.to_string()).to_string()); builder.commit_row(); return; } @@ -324,8 +320,7 @@ pub fn register(registry: &mut FunctionRegistry) { let multi_point: MultiPoint = match g.try_into() { Ok(multi_point) => multi_point, Err(e) => { - ctx.set_error(builder.len(), e.to_string()); - builder.put_str(""); + ctx.set_error(builder.len(), ErrorCode::GeometryError(e.to_string()).to_string()); builder.commit_row(); return; } @@ -339,7 +334,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError("Geometry expression must be a Point, MultiPoint, or LineString.").to_string(), ); - builder.put_str(""); builder.commit_row(); return; } @@ -570,7 +564,6 @@ pub fn register(registry: &mut FunctionRegistry) { builder.len(), ErrorCode::GeometryError(e.to_string()).to_string(), ); - builder.put_str(""); } } builder.commit_row(); diff --git a/src/query/sql/src/planner/binder/binder.rs b/src/query/sql/src/planner/binder/binder.rs index 9bf5e3d7315e4..ff59a7acbd90b 100644 --- a/src/query/sql/src/planner/binder/binder.rs +++ b/src/query/sql/src/planner/binder/binder.rs @@ -53,7 +53,6 @@ use crate::plans::DropConnectionPlan; use crate::plans::DropFileFormatPlan; use crate::plans::DropRolePlan; use crate::plans::DropStagePlan; -use crate::plans::DropUDFPlan; use crate::plans::DropUserPlan; use crate::plans::MaterializedCte; use crate::plans::Plan; @@ -479,10 +478,7 @@ impl<'a> Binder { Statement::DropUDF { if_exists, udf_name, - } => Plan::DropUDF(Box::new(DropUDFPlan { - if_exists: *if_exists, - udf: udf_name.to_string(), - })), + } => self.bind_drop_udf(*if_exists, udf_name).await?, Statement::Call(stmt) => self.bind_call(bind_context, stmt).await?, Statement::Presign(stmt) => self.bind_presign(bind_context, stmt).await?, diff --git a/src/query/sql/src/planner/binder/udf.rs b/src/query/sql/src/planner/binder/udf.rs index d9c461ebb2b96..7f549565c5bc9 100644 --- a/src/query/sql/src/planner/binder/udf.rs +++ b/src/query/sql/src/planner/binder/udf.rs @@ -28,10 +28,12 @@ use databend_common_meta_app::principal::UDFScript; use databend_common_meta_app::principal::UDFServer; use databend_common_meta_app::principal::UserDefinedFunction; +use crate::normalize_identifier; use crate::planner::resolve_type_name; use crate::planner::udf_validator::UDFValidator; use crate::plans::AlterUDFPlan; use crate::plans::CreateUDFPlan; +use crate::plans::DropUDFPlan; use crate::plans::Plan; use crate::Binder; @@ -42,13 +44,14 @@ impl Binder { udf_description: &Option, udf_definition: &UDFDefinition, ) -> Result { + let name = normalize_identifier(udf_name, &self.name_resolution_ctx).to_string(); match udf_definition { UDFDefinition::LambdaUDF { parameters, definition, } => { let mut validator = UDFValidator { - name: udf_name.to_string(), + name, parameters: parameters.iter().map(|v| v.to_string()).collect(), ..Default::default() }; @@ -107,7 +110,7 @@ impl Binder { .await?; Ok(UserDefinedFunction { - name: udf_name.to_string(), + name, description: udf_description.clone().unwrap_or_default(), definition: PlanUDFDefinition::UDFServer(UDFServer { address: address.clone(), @@ -152,7 +155,7 @@ impl Binder { } Ok(UserDefinedFunction { - name: udf_name.to_string(), + name, description: udf_description.clone().unwrap_or_default(), definition: PlanUDFDefinition::UDFScript(UDFScript { code: code.clone(), @@ -190,4 +193,16 @@ impl Binder { .await?; Ok(Plan::AlterUDF(Box::new(AlterUDFPlan { udf }))) } + + pub(in crate::planner::binder) async fn bind_drop_udf( + &mut self, + if_exists: bool, + udf_name: &Identifier, + ) -> Result { + let name = normalize_identifier(udf_name, &self.name_resolution_ctx).to_string(); + Ok(Plan::DropUDF(Box::new(DropUDFPlan { + if_exists, + udf: name, + }))) + } } diff --git a/tests/sqllogictests/suites/base/05_ddl/05_0010_ddl_create_udf.test b/tests/sqllogictests/suites/base/05_ddl/05_0010_ddl_create_udf.test index 10d9172bfc22a..11299fb45e157 100644 --- a/tests/sqllogictests/suites/base/05_ddl/05_0010_ddl_create_udf.test +++ b/tests/sqllogictests/suites/base/05_ddl/05_0010_ddl_create_udf.test @@ -72,3 +72,57 @@ CREATE OR REPLACE FUNCTION isnotempty_test_replace AS(p) -> not(is_null(p)) DES statement ok DROP FUNCTION IF EXISTS isnotempty_test_replace; + +statement ok +create or replace function SOME_NAME as (x) -> x * x + +query I +SELECT SOME_NAME(2) +---- +4 + +query I +SELECT some_name(2) +---- +4 + +statement ok +alter function SOME_NAME as (x) -> x * x + 1 + +query I +SELECT SOME_NAME(2) +---- +5 + +query I +SELECT some_name(2) +---- +5 + +statement ok +drop function SOME_NAME + +statement ok +create or replace function `SOME_NAME` as (x) -> x * x + +query I +SELECT `SOME_NAME`(2) +---- +4 + +statement error 1008 +SELECT SOME_NAME(2) + +statement error 1008 +SELECT `some_name`(2) + +statement ok +alter function `SOME_NAME` as (x) -> x * x + 1 + +query I +SELECT `SOME_NAME`(2) +---- +5 + +statement ok +drop function `SOME_NAME`