@@ -106,7 +106,7 @@ use itertools::Itertools;
106
106
use jsonb:: keypath:: KeyPath ;
107
107
use jsonb:: keypath:: KeyPaths ;
108
108
use simsearch:: SimSearch ;
109
- use unicase:: UniCase ;
109
+ use unicase:: Ascii ;
110
110
111
111
use super :: name_resolution:: NameResolutionContext ;
112
112
use super :: normalize_identifier;
@@ -185,7 +185,7 @@ pub struct TypeChecker<'a> {
185
185
// This is used to check if there is nested aggregate function.
186
186
in_aggregate_function : bool ,
187
187
188
- // true if current expr is inside an window function.
188
+ // true if current expr is inside a window function.
189
189
// This is used to allow aggregation function in window's aggregate function.
190
190
in_window_function : bool ,
191
191
forbid_udf : bool ,
@@ -722,7 +722,10 @@ impl<'a> TypeChecker<'a> {
722
722
} => {
723
723
let func_name = normalize_identifier ( name, self . name_resolution_ctx ) . to_string ( ) ;
724
724
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
+ {
726
729
if let Some ( udf) = self . resolve_udf ( * span, func_name, args) ? {
727
730
return Ok ( udf) ;
728
731
} else {
@@ -731,10 +734,10 @@ impl<'a> TypeChecker<'a> {
731
734
. all_function_names ( )
732
735
. into_iter ( )
733
736
. 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 ( ) ) )
738
741
. chain (
739
742
Self :: all_sugar_functions ( )
740
743
. iter ( )
@@ -768,15 +771,15 @@ impl<'a> TypeChecker<'a> {
768
771
// check window function legal
769
772
if window. is_some ( )
770
773
&& !AggregateFunctionFactory :: instance ( ) . contains ( func_name)
771
- && !GENERAL_WINDOW_FUNCTIONS . contains ( & func_name )
774
+ && !GENERAL_WINDOW_FUNCTIONS . contains ( & uni_case_func_name )
772
775
{
773
776
return Err ( ErrorCode :: SemanticError (
774
777
"only window and aggregate functions allowed in window syntax" ,
775
778
)
776
779
. set_span ( * span) ) ;
777
780
}
778
781
// 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 ) {
780
783
return Err ( ErrorCode :: SemanticError (
781
784
"only lambda functions allowed in lambda syntax" ,
782
785
)
@@ -785,7 +788,7 @@ impl<'a> TypeChecker<'a> {
785
788
786
789
let args: Vec < & Expr > = args. iter ( ) . collect ( ) ;
787
790
788
- if GENERAL_WINDOW_FUNCTIONS . contains ( & func_name ) {
791
+ if GENERAL_WINDOW_FUNCTIONS . contains ( & uni_case_func_name ) {
789
792
// general window function
790
793
if window. is_none ( ) {
791
794
return Err ( ErrorCode :: SemanticError ( format ! (
@@ -851,7 +854,7 @@ impl<'a> TypeChecker<'a> {
851
854
// aggregate function
852
855
Box :: new ( ( new_agg_func. into ( ) , data_type) )
853
856
}
854
- } else if GENERAL_LAMBDA_FUNCTIONS . contains ( & func_name ) {
857
+ } else if GENERAL_LAMBDA_FUNCTIONS . contains ( & uni_case_func_name ) {
855
858
if lambda. is_none ( ) {
856
859
return Err ( ErrorCode :: SemanticError ( format ! (
857
860
"function {func_name} must have a lambda expression" ,
@@ -860,8 +863,8 @@ impl<'a> TypeChecker<'a> {
860
863
}
861
864
let lambda = lambda. as_ref ( ) . unwrap ( ) ;
862
865
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 ( ) {
865
868
"score" => self . resolve_score_search_function ( * span, func_name, & args) ?,
866
869
"match" => self . resolve_match_search_function ( * span, func_name, & args) ?,
867
870
"query" => self . resolve_query_search_function ( * span, func_name, & args) ?,
@@ -873,7 +876,7 @@ impl<'a> TypeChecker<'a> {
873
876
. set_span ( * span) ) ;
874
877
}
875
878
}
876
- } else if ASYNC_FUNCTIONS . contains ( & func_name ) {
879
+ } else if ASYNC_FUNCTIONS . contains ( & uni_case_func_name ) {
877
880
self . resolve_async_function ( * span, func_name, & args) ?
878
881
} else if BUILTIN_FUNCTIONS
879
882
. get_property ( func_name)
@@ -1435,7 +1438,7 @@ impl<'a> TypeChecker<'a> {
1435
1438
self . in_window_function = false ;
1436
1439
1437
1440
// 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).
1439
1442
let ignore_null = if let Some ( ignore_null) = window_ignore_null {
1440
1443
* ignore_null
1441
1444
} else {
@@ -2080,7 +2083,7 @@ impl<'a> TypeChecker<'a> {
2080
2083
param_count : usize ,
2081
2084
span : Span ,
2082
2085
) -> 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.
2084
2087
let expected_count = if func_name == "array_reduce" {
2085
2088
2
2086
2089
} else if func_name. starts_with ( "array" ) {
@@ -3153,11 +3156,6 @@ impl<'a> TypeChecker<'a> {
3153
3156
FUNCTIONS
3154
3157
}
3155
3158
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
-
3161
3159
fn try_rewrite_sugar_function (
3162
3160
& mut self ,
3163
3161
span : Span ,
0 commit comments