From 5858a3c74729291f7722815787dd8b7cdfe86dff Mon Sep 17 00:00:00 2001 From: Michael Xu Date: Mon, 19 Feb 2024 12:38:03 -0500 Subject: [PATCH] use SQL_UDF_PATTERN instead of manual encoding --- src/frontend/src/binder/expr/column.rs | 3 ++- src/frontend/src/binder/expr/mod.rs | 14 +++++++------- src/frontend/src/handler/create_sql_function.rs | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/frontend/src/binder/expr/column.rs b/src/frontend/src/binder/expr/column.rs index 369dcc4e2d2b3..38dcf11ba207f 100644 --- a/src/frontend/src/binder/expr/column.rs +++ b/src/frontend/src/binder/expr/column.rs @@ -18,6 +18,7 @@ use risingwave_sqlparser::ast::Ident; use crate::binder::Binder; use crate::error::{ErrorCode, Result}; use crate::expr::{CorrelatedInputRef, ExprImpl, ExprType, FunctionCall, InputRef, Literal}; +use crate::handler::create_sql_function::SQL_UDF_PATTERN; impl Binder { pub fn bind_column(&mut self, idents: &[Ident]) -> Result { @@ -57,7 +58,7 @@ impl Binder { // Note: the error message here also help with hint display // when invalid definition occurs at sql udf creation time return Err(ErrorCode::BindError(format!( - "[sql udf] failed to find named parameter {column_name}" + "{SQL_UDF_PATTERN} failed to find named parameter {column_name}" )) .into()); } diff --git a/src/frontend/src/binder/expr/mod.rs b/src/frontend/src/binder/expr/mod.rs index ebdc6c8679877..fd61cf205ac03 100644 --- a/src/frontend/src/binder/expr/mod.rs +++ b/src/frontend/src/binder/expr/mod.rs @@ -27,6 +27,7 @@ use crate::binder::expr::function::SYS_FUNCTION_WITHOUT_ARGS; use crate::binder::Binder; use crate::error::{ErrorCode, Result, RwError}; use crate::expr::{Expr as _, ExprImpl, ExprType, FunctionCall, InputRef, Parameter, SubqueryKind}; +use crate::handler::create_sql_function::SQL_UDF_PATTERN; mod binary_op; mod column; @@ -392,14 +393,13 @@ impl Binder { if self.udf_context.global_count() != 0 { if let Some(expr) = self.udf_context.get_expr(&format!("${index}")) { return Ok(expr.clone()); - } else { - // Same as `bind_column`, the error message here - // help with hint display when invalid definition occurs - return Err(ErrorCode::BindError(format!( - "[sql udf] failed to find unnamed parameter ${index}" - )) - .into()); } + // Same as `bind_column`, the error message here + // help with hint display when invalid definition occurs + return Err(ErrorCode::BindError(format!( + "{SQL_UDF_PATTERN} failed to find unnamed parameter ${index}" + )) + .into()); } Ok(Parameter::new(index, self.param_types.clone()).into()) diff --git a/src/frontend/src/handler/create_sql_function.rs b/src/frontend/src/handler/create_sql_function.rs index b7d63b66fc5bb..dc4338ae9e0cd 100644 --- a/src/frontend/src/handler/create_sql_function.rs +++ b/src/frontend/src/handler/create_sql_function.rs @@ -36,7 +36,7 @@ const DEFAULT_ERR_MSG: &str = "Failed to conduct semantic check"; const PROMPT: &str = "In SQL UDF definition: "; -const SQL_UDF_PATTERN: &str = "[sql udf]"; +pub const SQL_UDF_PATTERN: &str = "[sql udf]"; /// Create a mock `udf_context`, which is used for semantic check fn create_mock_udf_context(