Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: search by lowercase function name #16866

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/query/sql/src/planner/semantic/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,8 +721,9 @@ 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)
let func_name_lowercase = func_name.to_lowercase();
if !is_builtin_function(&func_name_lowercase)
&& !Self::all_sugar_functions().contains(&func_name_lowercase.as_str())
{
if let Some(udf) = self.resolve_udf(*span, func_name, args)? {
return Ok(udf);
Expand Down
54 changes: 54 additions & 0 deletions src/query/sql/tests/type_checker.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Copyright 2022 Datafuse Labs.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use databend_common_ast::parser::parse_expr;
use databend_common_ast::parser::tokenize_sql;
use databend_common_ast::parser::Dialect;
use databend_common_ast::ast::Expr;
use databend_common_catalog::table_context::TableContext;
use databend_common_sql::BindContext;
use databend_common_sql::MetadataRef;
use databend_query::sql::NameResolutionContext;
use databend_common_sql::TypeChecker;

#[test]
fn test_resolve_function_call_name() {
let mut bind_context = BindContext::default();
let table_context = Arc::new(TableContext::new());
let name_resolution_ctx = NameResolutionContext {
unquoted_ident_case_sensitive: true,
quoted_ident_case_sensitive: true,
deny_column_reference: false,
};
let metadata = MetadataRef::default();
let aliases = vec![];

let type_checker = TypeChecker::try_create(
&mut bind_context,
table_context,
&name_resolution_ctx,
metadata,
&aliases,
false,
);

let tokens = tokenize_sql("SELECT VERSION();").unwrap();
let mut expr = parse_expr(&tokens, Dialect::Mysql).unwrap();

if let Ok(mut checker) = type_checker {
let result = checker.resolve(&expr);

assert!(result.is_ok(), "Function resolution failed");
}
}
Loading