@@ -23,8 +23,10 @@ use crate::catalog::{ColumnCatalog, ColumnDesc, ColumnRef, TableName};
2323use crate :: db:: { BindSource , DBTransaction , Database , DatabaseIter , TransactionIter } ;
2424use crate :: errors:: { DatabaseError , SqlErrorSpan } ;
2525use crate :: expression;
26+ use crate :: expression:: agg:: AggKind ;
2627use crate :: expression:: simplify:: ConstantCalculator ;
2728use crate :: expression:: visitor_mut:: ExprVisitorMut ;
29+ use crate :: expression:: window:: WindowFunctionKind ;
2830use crate :: expression:: { AliasType , ScalarExpression } ;
2931use crate :: iter_ext:: Itertools ;
3032use crate :: parser:: parse_sql;
@@ -2440,18 +2442,30 @@ impl<'a, 'parent, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<
24402442 . to_string ( ) ,
24412443 ) ) ;
24422444 }
2445+ let Some ( kind) = WindowFunctionKind :: from_name ( & function_name) else {
2446+ return Err ( attach_span_if_absent (
2447+ DatabaseError :: UnsupportedStmt ( format ! (
2448+ "window function `{function_name}` is not supported"
2449+ ) ) ,
2450+ func_span,
2451+ ) ) ;
2452+ } ;
24432453 return self
2444- . bind_window_call ( function_name , args, is_distinct, over, arena)
2454+ . bind_window_call ( kind , args, is_distinct, over, arena)
24452455 . map_err ( |err| attach_span_if_absent ( err, func_span) ) ;
24462456 }
24472457
2448- self . bind_function_call ( function_name, args, is_distinct, arena)
2449- . map_err ( |err| attach_span_if_absent ( err, func_span) )
2458+ let result = if let Some ( kind) = AggKind :: from_name ( & function_name) {
2459+ self . bind_aggregate_function ( kind, args, is_distinct, arena)
2460+ } else {
2461+ self . bind_function_call ( function_name, args, arena)
2462+ } ;
2463+ result. map_err ( |err| attach_span_if_absent ( err, func_span) )
24502464 }
24512465
24522466 fn bind_window_call (
24532467 & mut self ,
2454- function_name : String ,
2468+ kind : WindowFunctionKind ,
24552469 args : Vec < ScalarExpression > ,
24562470 is_distinct : bool ,
24572471 over : & WindowType ,
@@ -2502,7 +2516,7 @@ impl<'a, 'parent, T: Transaction, A: AsRef<[(&'static str, DataValue)]>> Binder<
25022516 ) )
25032517 } )
25042518 . collect :: < Result < Vec < _ > , DatabaseError > > ( ) ?;
2505- self . bind_window_function ( function_name , args, partition_by, order_by, arena)
2519+ self . bind_window_function ( kind , args, partition_by, order_by, arena)
25062520 }
25072521
25082522 pub fn bind_set_expr (
0 commit comments