Skip to content

Commit

Permalink
use SQL_UDF_PATTERN instead of manual encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhseh committed Feb 19, 2024
1 parent 974455a commit 5858a3c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/frontend/src/binder/expr/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ExprImpl> {
Expand Down Expand Up @@ -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());
}
Expand Down
14 changes: 7 additions & 7 deletions src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion src/frontend/src/handler/create_sql_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5858a3c

Please sign in to comment.