@@ -106,7 +106,7 @@ use itertools::Itertools;
106106use jsonb:: keypath:: KeyPath ;
107107use jsonb:: keypath:: KeyPaths ;
108108use simsearch:: SimSearch ;
109- use unicase:: UniCase ;
109+ use unicase:: Ascii ;
110110
111111use super :: name_resolution:: NameResolutionContext ;
112112use super :: normalize_identifier;
@@ -185,7 +185,7 @@ pub struct TypeChecker<'a> {
185185 // This is used to check if there is nested aggregate function.
186186 in_aggregate_function : bool ,
187187
188- // true if current expr is inside an window function.
188+ // true if current expr is inside a window function.
189189 // This is used to allow aggregation function in window's aggregate function.
190190 in_window_function : bool ,
191191 forbid_udf : bool ,
@@ -722,7 +722,10 @@ impl<'a> TypeChecker<'a> {
722722 } => {
723723 let func_name = normalize_identifier ( name, self . name_resolution_ctx ) . to_string ( ) ;
724724 let func_name = func_name. as_str ( ) ;
725- if !is_builtin_function ( func_name) && !Self :: is_sugar_function ( func_name) {
725+ let uni_case_func_name = Ascii :: new ( func_name) ;
726+ if !is_builtin_function ( func_name)
727+ && !Self :: all_sugar_functions ( ) . contains ( & uni_case_func_name)
728+ {
726729 if let Some ( udf) = self . resolve_udf ( * span, func_name, args) ? {
727730 return Ok ( udf) ;
728731 } else {
@@ -731,10 +734,10 @@ impl<'a> TypeChecker<'a> {
731734 . all_function_names ( )
732735 . into_iter ( )
733736 . chain ( AggregateFunctionFactory :: instance ( ) . registered_names ( ) )
734- . chain ( GENERAL_WINDOW_FUNCTIONS . iter ( ) . cloned ( ) . map ( str :: to_string ) )
735- . chain ( GENERAL_LAMBDA_FUNCTIONS . iter ( ) . cloned ( ) . map ( str :: to_string ) )
736- . chain ( GENERAL_SEARCH_FUNCTIONS . iter ( ) . cloned ( ) . map ( str :: to_string ) )
737- . chain ( ASYNC_FUNCTIONS . iter ( ) . cloned ( ) . map ( str :: to_string ) )
737+ . chain ( GENERAL_WINDOW_FUNCTIONS . iter ( ) . cloned ( ) . map ( |ascii| ascii . into_inner ( ) ) )
738+ . chain ( GENERAL_LAMBDA_FUNCTIONS . iter ( ) . cloned ( ) . map ( |ascii| ascii . into_inner ( ) ) )
739+ . chain ( GENERAL_SEARCH_FUNCTIONS . iter ( ) . cloned ( ) . map ( |ascii| ascii . into_inner ( ) ) )
740+ . chain ( ASYNC_FUNCTIONS . iter ( ) . cloned ( ) . map ( |ascii| ascii . into_inner ( ) ) )
738741 . chain (
739742 Self :: all_sugar_functions ( )
740743 . iter ( )
@@ -768,15 +771,15 @@ impl<'a> TypeChecker<'a> {
768771 // check window function legal
769772 if window. is_some ( )
770773 && !AggregateFunctionFactory :: instance ( ) . contains ( func_name)
771- && !GENERAL_WINDOW_FUNCTIONS . contains ( & func_name )
774+ && !GENERAL_WINDOW_FUNCTIONS . contains ( & uni_case_func_name )
772775 {
773776 return Err ( ErrorCode :: SemanticError (
774777 "only window and aggregate functions allowed in window syntax" ,
775778 )
776779 . set_span ( * span) ) ;
777780 }
778781 // check lambda function legal
779- if lambda. is_some ( ) && !GENERAL_LAMBDA_FUNCTIONS . contains ( & func_name ) {
782+ if lambda. is_some ( ) && !GENERAL_LAMBDA_FUNCTIONS . contains ( & uni_case_func_name ) {
780783 return Err ( ErrorCode :: SemanticError (
781784 "only lambda functions allowed in lambda syntax" ,
782785 )
@@ -785,7 +788,7 @@ impl<'a> TypeChecker<'a> {
785788
786789 let args: Vec < & Expr > = args. iter ( ) . collect ( ) ;
787790
788- if GENERAL_WINDOW_FUNCTIONS . contains ( & func_name ) {
791+ if GENERAL_WINDOW_FUNCTIONS . contains ( & uni_case_func_name ) {
789792 // general window function
790793 if window. is_none ( ) {
791794 return Err ( ErrorCode :: SemanticError ( format ! (
@@ -851,7 +854,7 @@ impl<'a> TypeChecker<'a> {
851854 // aggregate function
852855 Box :: new ( ( new_agg_func. into ( ) , data_type) )
853856 }
854- } else if GENERAL_LAMBDA_FUNCTIONS . contains ( & func_name ) {
857+ } else if GENERAL_LAMBDA_FUNCTIONS . contains ( & uni_case_func_name ) {
855858 if lambda. is_none ( ) {
856859 return Err ( ErrorCode :: SemanticError ( format ! (
857860 "function {func_name} must have a lambda expression" ,
@@ -860,8 +863,8 @@ impl<'a> TypeChecker<'a> {
860863 }
861864 let lambda = lambda. as_ref ( ) . unwrap ( ) ;
862865 self . resolve_lambda_function ( * span, func_name, & args, lambda) ?
863- } else if GENERAL_SEARCH_FUNCTIONS . contains ( & func_name ) {
864- match func_name {
866+ } else if GENERAL_SEARCH_FUNCTIONS . contains ( & uni_case_func_name ) {
867+ match func_name. to_lowercase ( ) . as_str ( ) {
865868 "score" => self . resolve_score_search_function ( * span, func_name, & args) ?,
866869 "match" => self . resolve_match_search_function ( * span, func_name, & args) ?,
867870 "query" => self . resolve_query_search_function ( * span, func_name, & args) ?,
@@ -873,7 +876,7 @@ impl<'a> TypeChecker<'a> {
873876 . set_span ( * span) ) ;
874877 }
875878 }
876- } else if ASYNC_FUNCTIONS . contains ( & func_name ) {
879+ } else if ASYNC_FUNCTIONS . contains ( & uni_case_func_name ) {
877880 self . resolve_async_function ( * span, func_name, & args) ?
878881 } else if BUILTIN_FUNCTIONS
879882 . get_property ( func_name)
@@ -1435,7 +1438,7 @@ impl<'a> TypeChecker<'a> {
14351438 self . in_window_function = false ;
14361439
14371440 // If { IGNORE | RESPECT } NULLS is not specified, the default is RESPECT NULLS
1438- // (i.e. a NULL value will be returned if the expression contains a NULL value and it is the first value in the expression).
1441+ // (i.e. a NULL value will be returned if the expression contains a NULL value, and it is the first value in the expression).
14391442 let ignore_null = if let Some ( ignore_null) = window_ignore_null {
14401443 * ignore_null
14411444 } else {
@@ -2080,7 +2083,7 @@ impl<'a> TypeChecker<'a> {
20802083 param_count : usize ,
20812084 span : Span ,
20822085 ) -> Result < ( ) > {
2083- // json lambda functions are casted to array or map, ignored here.
2086+ // json lambda functions are cast to array or map, ignored here.
20842087 let expected_count = if func_name == "array_reduce" {
20852088 2
20862089 } else if func_name. starts_with ( "array" ) {
@@ -3153,11 +3156,6 @@ impl<'a> TypeChecker<'a> {
31533156 FUNCTIONS
31543157 }
31553158
3156- pub fn is_sugar_function ( name : & str ) -> bool {
3157- let name = Ascii :: new ( name) ;
3158- all_sugar_functions ( ) . iter ( ) . any ( |func| func. eq ( & name) )
3159- }
3160-
31613159 fn try_rewrite_sugar_function (
31623160 & mut self ,
31633161 span : Span ,
0 commit comments