Skip to content

Commit

Permalink
add method to check sugar function
Browse files Browse the repository at this point in the history
  • Loading branch information
notauserx committed Nov 22, 2024
1 parent 6bc928e commit 77b7727
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,9 +721,7 @@ impl<'a> TypeChecker<'a> {
} => {
let func_name = normalize_identifier(name, self.name_resolution_ctx).to_string();
let func_name = func_name.as_str();
if !is_builtin_function(func_name)
&& !Self::all_sugar_functions().contains(&func_name)
{
if !is_builtin_function(func_name) && !Self::is_sugar_function(func_name) {
if let Some(udf) = self.resolve_udf(*span, func_name, args)? {
return Ok(udf);
} else {
Expand Down Expand Up @@ -3153,6 +3151,12 @@ impl<'a> TypeChecker<'a> {
]
}

pub fn is_sugar_function(name: &str) -> bool {
Self::all_sugar_functions()
.into_iter()
.any(|func| func.eq_ignore_ascii_case(name))
}

fn try_rewrite_sugar_function(
&mut self,
span: Span,
Expand Down
10 changes: 10 additions & 0 deletions src/query/sql/tests/type_check.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use databend_common_sql::TypeChecker;

#[test]
fn test_is_sugar_function_match() {
assert!(TypeChecker::is_sugar_function("database"));
assert!(TypeChecker::is_sugar_function("DATABASE"));
assert!(TypeChecker::is_sugar_function("version"));
assert!(TypeChecker::is_sugar_function("VERSION"));
assert!(TypeChecker::is_sugar_function("current_user"));
}

0 comments on commit 77b7727

Please sign in to comment.