Skip to content

Commit e6bb4c5

Browse files
committed
Remove BuiltInWindowFunction
1 parent 67ee5be commit e6bb4c5

File tree

12 files changed

+23
-349
lines changed

12 files changed

+23
-349
lines changed

datafusion/expr/src/built_in_window_function.rs

Lines changed: 0 additions & 131 deletions
This file was deleted.

datafusion/expr/src/expr.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@ use crate::expr_fn::binary_expr;
2727
use crate::logical_plan::Subquery;
2828
use crate::utils::expr_to_columns;
2929
use crate::Volatility;
30-
use crate::{
31-
udaf, BuiltInWindowFunction, ExprSchemable, Operator, Signature, WindowFrame,
32-
WindowUDF,
33-
};
30+
use crate::{udaf, ExprSchemable, Operator, Signature, WindowFrame, WindowUDF};
3431

3532
use arrow::datatypes::{DataType, FieldRef};
3633
use datafusion_common::cse::HashNode;
@@ -697,13 +694,13 @@ impl AggregateFunction {
697694
}
698695
}
699696

700-
/// WindowFunction
697+
/// A function used as a SQL window function
698+
///
699+
/// In SQL, you can use:
700+
/// - Actual window functions ([`WindowUDF`])
701+
/// - Noraml aggregate functions ([`AggregateUDF`])
701702
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
702-
/// Defines which implementation of an aggregate function DataFusion should call.
703703
pub enum WindowFunctionDefinition {
704-
/// A built in aggregate function that leverages an aggregate function
705-
/// A a built-in window function
706-
BuiltInWindowFunction(BuiltInWindowFunction),
707704
/// A user defined aggregate function
708705
AggregateUDF(Arc<crate::AggregateUDF>),
709706
/// A user defined aggregate function
@@ -719,9 +716,6 @@ impl WindowFunctionDefinition {
719716
display_name: &str,
720717
) -> Result<DataType> {
721718
match self {
722-
WindowFunctionDefinition::BuiltInWindowFunction(fun) => {
723-
fun.return_type(input_expr_types)
724-
}
725719
WindowFunctionDefinition::AggregateUDF(fun) => {
726720
fun.return_type(input_expr_types)
727721
}
@@ -734,7 +728,6 @@ impl WindowFunctionDefinition {
734728
/// The signatures supported by the function `fun`.
735729
pub fn signature(&self) -> Signature {
736730
match self {
737-
WindowFunctionDefinition::BuiltInWindowFunction(fun) => fun.signature(),
738731
WindowFunctionDefinition::AggregateUDF(fun) => fun.signature().clone(),
739732
WindowFunctionDefinition::WindowUDF(fun) => fun.signature().clone(),
740733
}
@@ -743,7 +736,6 @@ impl WindowFunctionDefinition {
743736
/// Function's name for display
744737
pub fn name(&self) -> &str {
745738
match self {
746-
WindowFunctionDefinition::BuiltInWindowFunction(fun) => fun.name(),
747739
WindowFunctionDefinition::WindowUDF(fun) => fun.name(),
748740
WindowFunctionDefinition::AggregateUDF(fun) => fun.name(),
749741
}
@@ -753,19 +745,12 @@ impl WindowFunctionDefinition {
753745
impl Display for WindowFunctionDefinition {
754746
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
755747
match self {
756-
WindowFunctionDefinition::BuiltInWindowFunction(fun) => Display::fmt(fun, f),
757748
WindowFunctionDefinition::AggregateUDF(fun) => Display::fmt(fun, f),
758749
WindowFunctionDefinition::WindowUDF(fun) => Display::fmt(fun, f),
759750
}
760751
}
761752
}
762753

763-
impl From<BuiltInWindowFunction> for WindowFunctionDefinition {
764-
fn from(value: BuiltInWindowFunction) -> Self {
765-
Self::BuiltInWindowFunction(value)
766-
}
767-
}
768-
769754
impl From<Arc<crate::AggregateUDF>> for WindowFunctionDefinition {
770755
fn from(value: Arc<crate::AggregateUDF>) -> Self {
771756
Self::AggregateUDF(value)

datafusion/expr/src/expr_schema.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,6 @@ impl Expr {
481481
.map(|e| e.get_type(schema))
482482
.collect::<Result<Vec<_>>>()?;
483483
match fun {
484-
WindowFunctionDefinition::BuiltInWindowFunction(window_fun) => {
485-
let return_type = window_fun.return_type(&data_types)?;
486-
let nullable =
487-
!["RANK", "NTILE", "CUME_DIST"].contains(&window_fun.name());
488-
Ok((return_type, nullable))
489-
}
490484
WindowFunctionDefinition::AggregateUDF(udaf) => {
491485
let new_types = data_types_with_aggregate_udf(&data_types, udaf)
492486
.map_err(|err| {

datafusion/expr/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
//!
2929
//! The [expr_fn] module contains functions for creating expressions.
3030
31-
mod built_in_window_function;
3231
mod literal;
3332
mod operation;
3433
mod partition_evaluator;
@@ -67,7 +66,6 @@ pub mod var_provider;
6766
pub mod window_frame;
6867
pub mod window_state;
6968

70-
pub use built_in_window_function::BuiltInWindowFunction;
7169
pub use datafusion_expr_common::accumulator::Accumulator;
7270
pub use datafusion_expr_common::columnar_value::ColumnarValue;
7371
pub use datafusion_expr_common::groups_accumulator::{EmitTo, GroupsAccumulator};

datafusion/expr/src/udwf.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ use datafusion_functions_window_common::field::WindowUDFFieldArgs;
3939
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
4040
use datafusion_physical_expr_common::physical_expr::PhysicalExpr;
4141

42-
/// Logical representation of a user-defined window function (UDWF)
43-
/// A UDWF is different from a UDF in that it is stateful across batches.
42+
/// Logical representation of a user-defined window function (UDWF).
43+
///
44+
/// A Window Function is called via the SQL `OVER` clause:
45+
///
46+
/// ```sql
47+
/// SELECT first_value(col) OVER (PARTITION BY a, b ORDER BY c) FROM foo;
48+
/// ```
49+
///
50+
/// A UDWF is different from a user defined function (UDF) in that it is
51+
/// stateful across batches.
4452
///
4553
/// See the documentation on [`PartitionEvaluator`] for more details
4654
///

datafusion/physical-plan/src/windows/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,6 @@ pub fn create_window_expr(
103103
ignore_nulls: bool,
104104
) -> Result<Arc<dyn WindowExpr>> {
105105
Ok(match fun {
106-
WindowFunctionDefinition::BuiltInWindowFunction(_fun) => {
107-
unreachable!()
108-
}
109106
WindowFunctionDefinition::AggregateUDF(fun) => {
110107
let aggregate = AggregateExprBuilder::new(Arc::clone(fun), args.to_vec())
111108
.schema(Arc::new(input_schema.clone()))
@@ -120,7 +117,6 @@ pub fn create_window_expr(
120117
aggregate,
121118
)
122119
}
123-
// TODO: Ordering not supported for Window UDFs yet
124120
WindowFunctionDefinition::WindowUDF(fun) => Arc::new(BuiltInWindowExpr::new(
125121
create_udwf_window_expr(fun, args, input_schema, name, ignore_nulls)?,
126122
partition_by,

datafusion/proto/proto/datafusion.proto

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -507,24 +507,9 @@ message ScalarUDFExprNode {
507507
optional bytes fun_definition = 3;
508508
}
509509

510-
enum BuiltInWindowFunction {
511-
UNSPECIFIED = 0; // https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum
512-
// ROW_NUMBER = 0;
513-
// RANK = 1;
514-
// DENSE_RANK = 2;
515-
// PERCENT_RANK = 3;
516-
// CUME_DIST = 4;
517-
// NTILE = 5;
518-
// LAG = 6;
519-
// LEAD = 7;
520-
// FIRST_VALUE = 8;
521-
// LAST_VALUE = 9;
522-
// NTH_VALUE = 10;
523-
}
524-
525510
message WindowExprNode {
526511
oneof window_function {
527-
BuiltInWindowFunction built_in_function = 2;
512+
// BuiltInWindowFunction built_in_function = 2;
528513
string udaf = 3;
529514
string udwf = 9;
530515
}
@@ -866,7 +851,7 @@ message PhysicalAggregateExprNode {
866851

867852
message PhysicalWindowExprNode {
868853
oneof window_function {
869-
BuiltInWindowFunction built_in_function = 2;
854+
// BuiltInWindowFunction built_in_function = 2;
870855
string user_defined_aggr_function = 3;
871856
}
872857
repeated PhysicalExprNode args = 4;

0 commit comments

Comments
 (0)