@@ -21,17 +21,13 @@ use std::collections::{HashMap, HashSet};
21
21
use std:: fmt:: { self , Display , Formatter , Write } ;
22
22
use std:: hash:: { Hash , Hasher } ;
23
23
use std:: mem;
24
- use std:: str:: FromStr ;
25
24
use std:: sync:: Arc ;
26
25
27
26
use crate :: expr_fn:: binary_expr;
28
27
use crate :: logical_plan:: Subquery ;
29
28
use crate :: utils:: expr_to_columns;
30
29
use crate :: Volatility ;
31
- use crate :: {
32
- udaf, BuiltInWindowFunction , ExprSchemable , Operator , Signature , WindowFrame ,
33
- WindowUDF ,
34
- } ;
30
+ use crate :: { udaf, ExprSchemable , Operator , Signature , WindowFrame , WindowUDF } ;
35
31
36
32
use arrow:: datatypes:: { DataType , FieldRef } ;
37
33
use datafusion_common:: cse:: HashNode ;
@@ -693,9 +689,6 @@ impl AggregateFunction {
693
689
#[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Hash ) ]
694
690
/// Defines which implementation of an aggregate function DataFusion should call.
695
691
pub enum WindowFunctionDefinition {
696
- /// A built in aggregate function that leverages an aggregate function
697
- /// A a built-in window function
698
- BuiltInWindowFunction ( BuiltInWindowFunction ) ,
699
692
/// A user defined aggregate function
700
693
AggregateUDF ( Arc < crate :: AggregateUDF > ) ,
701
694
/// A user defined aggregate function
@@ -711,9 +704,6 @@ impl WindowFunctionDefinition {
711
704
display_name : & str ,
712
705
) -> Result < DataType > {
713
706
match self {
714
- WindowFunctionDefinition :: BuiltInWindowFunction ( fun) => {
715
- fun. return_type ( input_expr_types)
716
- }
717
707
WindowFunctionDefinition :: AggregateUDF ( fun) => {
718
708
fun. return_type ( input_expr_types)
719
709
}
@@ -726,7 +716,6 @@ impl WindowFunctionDefinition {
726
716
/// The signatures supported by the function `fun`.
727
717
pub fn signature ( & self ) -> Signature {
728
718
match self {
729
- WindowFunctionDefinition :: BuiltInWindowFunction ( fun) => fun. signature ( ) ,
730
719
WindowFunctionDefinition :: AggregateUDF ( fun) => fun. signature ( ) . clone ( ) ,
731
720
WindowFunctionDefinition :: WindowUDF ( fun) => fun. signature ( ) . clone ( ) ,
732
721
}
@@ -735,7 +724,6 @@ impl WindowFunctionDefinition {
735
724
/// Function's name for display
736
725
pub fn name ( & self ) -> & str {
737
726
match self {
738
- WindowFunctionDefinition :: BuiltInWindowFunction ( fun) => fun. name ( ) ,
739
727
WindowFunctionDefinition :: WindowUDF ( fun) => fun. name ( ) ,
740
728
WindowFunctionDefinition :: AggregateUDF ( fun) => fun. name ( ) ,
741
729
}
@@ -745,19 +733,12 @@ impl WindowFunctionDefinition {
745
733
impl Display for WindowFunctionDefinition {
746
734
fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
747
735
match self {
748
- WindowFunctionDefinition :: BuiltInWindowFunction ( fun) => Display :: fmt ( fun, f) ,
749
736
WindowFunctionDefinition :: AggregateUDF ( fun) => Display :: fmt ( fun, f) ,
750
737
WindowFunctionDefinition :: WindowUDF ( fun) => Display :: fmt ( fun, f) ,
751
738
}
752
739
}
753
740
}
754
741
755
- impl From < BuiltInWindowFunction > for WindowFunctionDefinition {
756
- fn from ( value : BuiltInWindowFunction ) -> Self {
757
- Self :: BuiltInWindowFunction ( value)
758
- }
759
- }
760
-
761
742
impl From < Arc < crate :: AggregateUDF > > for WindowFunctionDefinition {
762
743
fn from ( value : Arc < crate :: AggregateUDF > ) -> Self {
763
744
Self :: AggregateUDF ( value)
@@ -783,9 +764,10 @@ impl From<Arc<WindowUDF>> for WindowFunctionDefinition {
783
764
/// ```
784
765
/// # use datafusion_expr::{Expr, BuiltInWindowFunction, col, ExprFunctionExt};
785
766
/// # use datafusion_expr::expr::WindowFunction;
767
+ /// use datafusion_expr::WindowFunctionDefinition::WindowUDF;
786
768
/// // Create FIRST_VALUE(a) OVER (PARTITION BY b ORDER BY c)
787
769
/// let expr = Expr::WindowFunction(
788
- /// WindowFunction::new(BuiltInWindowFunction::FirstValue , vec![col("a")])
770
+ /// WindowFunction::new(WindowUDF:: , vec![col("a")])
789
771
/// )
790
772
/// .partition_by(vec![col("b")])
791
773
/// .order_by(vec![col("b").sort(true, true)])
@@ -823,23 +805,6 @@ impl WindowFunction {
823
805
}
824
806
}
825
807
826
- /// Find DataFusion's built-in window function by name.
827
- pub fn find_df_window_func ( name : & str ) -> Option < WindowFunctionDefinition > {
828
- let name = name. to_lowercase ( ) ;
829
- // Code paths for window functions leveraging ordinary aggregators and
830
- // built-in window functions are quite different, and the same function
831
- // may have different implementations for these cases. If the sought
832
- // function is not found among built-in window functions, we search for
833
- // it among aggregate functions.
834
- if let Ok ( built_in_function) = BuiltInWindowFunction :: from_str ( name. as_str ( ) ) {
835
- Some ( WindowFunctionDefinition :: BuiltInWindowFunction (
836
- built_in_function,
837
- ) )
838
- } else {
839
- None
840
- }
841
- }
842
-
843
808
/// EXISTS expression
844
809
#[ derive( Clone , PartialEq , Eq , PartialOrd , Hash , Debug ) ]
845
810
pub struct Exists {
@@ -2525,77 +2490,6 @@ mod test {
2525
2490
2526
2491
use super :: * ;
2527
2492
2528
- #[ test]
2529
- fn test_first_value_return_type ( ) -> Result < ( ) > {
2530
- let fun = find_df_window_func ( "first_value" ) . unwrap ( ) ;
2531
- let observed = fun. return_type ( & [ DataType :: Utf8 ] , & [ true ] , "" ) ?;
2532
- assert_eq ! ( DataType :: Utf8 , observed) ;
2533
-
2534
- let observed = fun. return_type ( & [ DataType :: UInt64 ] , & [ true ] , "" ) ?;
2535
- assert_eq ! ( DataType :: UInt64 , observed) ;
2536
-
2537
- Ok ( ( ) )
2538
- }
2539
-
2540
- #[ test]
2541
- fn test_last_value_return_type ( ) -> Result < ( ) > {
2542
- let fun = find_df_window_func ( "last_value" ) . unwrap ( ) ;
2543
- let observed = fun. return_type ( & [ DataType :: Utf8 ] , & [ true ] , "" ) ?;
2544
- assert_eq ! ( DataType :: Utf8 , observed) ;
2545
-
2546
- let observed = fun. return_type ( & [ DataType :: Float64 ] , & [ true ] , "" ) ?;
2547
- assert_eq ! ( DataType :: Float64 , observed) ;
2548
-
2549
- Ok ( ( ) )
2550
- }
2551
-
2552
- #[ test]
2553
- fn test_nth_value_return_type ( ) -> Result < ( ) > {
2554
- let fun = find_df_window_func ( "nth_value" ) . unwrap ( ) ;
2555
- let observed =
2556
- fun. return_type ( & [ DataType :: Utf8 , DataType :: UInt64 ] , & [ true , true ] , "" ) ?;
2557
- assert_eq ! ( DataType :: Utf8 , observed) ;
2558
-
2559
- let observed =
2560
- fun. return_type ( & [ DataType :: Float64 , DataType :: UInt64 ] , & [ true , true ] , "" ) ?;
2561
- assert_eq ! ( DataType :: Float64 , observed) ;
2562
-
2563
- Ok ( ( ) )
2564
- }
2565
-
2566
- #[ test]
2567
- fn test_window_function_case_insensitive ( ) -> Result < ( ) > {
2568
- let names = vec ! [ "first_value" , "last_value" , "nth_value" ] ;
2569
- for name in names {
2570
- let fun = find_df_window_func ( name) . unwrap ( ) ;
2571
- let fun2 = find_df_window_func ( name. to_uppercase ( ) . as_str ( ) ) . unwrap ( ) ;
2572
- assert_eq ! ( fun, fun2) ;
2573
- if fun. to_string ( ) == "first_value" || fun. to_string ( ) == "last_value" {
2574
- assert_eq ! ( fun. to_string( ) , name) ;
2575
- } else {
2576
- assert_eq ! ( fun. to_string( ) , name. to_uppercase( ) ) ;
2577
- }
2578
- }
2579
- Ok ( ( ) )
2580
- }
2581
-
2582
- #[ test]
2583
- fn test_find_df_window_function ( ) {
2584
- assert_eq ! (
2585
- find_df_window_func( "first_value" ) ,
2586
- Some ( WindowFunctionDefinition :: BuiltInWindowFunction (
2587
- BuiltInWindowFunction :: FirstValue
2588
- ) )
2589
- ) ;
2590
- assert_eq ! (
2591
- find_df_window_func( "LAST_value" ) ,
2592
- Some ( WindowFunctionDefinition :: BuiltInWindowFunction (
2593
- BuiltInWindowFunction :: LastValue
2594
- ) )
2595
- ) ;
2596
- assert_eq ! ( find_df_window_func( "not_exist" ) , None )
2597
- }
2598
-
2599
2493
#[ test]
2600
2494
fn test_display_wildcard ( ) {
2601
2495
assert_eq ! ( format!( "{}" , wildcard( ) ) , "*" ) ;
0 commit comments