diff --git a/datafusion/expr/src/built_in_window_function.rs b/datafusion/expr/src/built_in_window_function.rs deleted file mode 100644 index ab41395ad371..000000000000 --- a/datafusion/expr/src/built_in_window_function.rs +++ /dev/null @@ -1,131 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -//! Built-in functions module contains all the built-in functions definitions. - -use std::fmt; -use std::str::FromStr; - -use crate::type_coercion::functions::data_types; -use crate::utils; -use crate::{Signature, Volatility}; -use datafusion_common::{plan_datafusion_err, plan_err, DataFusionError, Result}; - -use arrow::datatypes::DataType; - -use strum_macros::EnumIter; - -impl fmt::Display for BuiltInWindowFunction { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name()) - } -} - -/// A [window function] built in to DataFusion -/// -/// [Window Function]: https://en.wikipedia.org/wiki/Window_function_(SQL) -#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash, EnumIter)] -pub enum BuiltInWindowFunction { - /// returns value evaluated at the row that is the first row of the window frame - FirstValue, - /// Returns value evaluated at the row that is the last row of the window frame - LastValue, - /// Returns value evaluated at the row that is the nth row of the window frame (counting from 1); returns null if no such row - NthValue, -} - -impl BuiltInWindowFunction { - pub fn name(&self) -> &str { - use BuiltInWindowFunction::*; - match self { - FirstValue => "first_value", - LastValue => "last_value", - NthValue => "NTH_VALUE", - } - } -} - -impl FromStr for BuiltInWindowFunction { - type Err = DataFusionError; - fn from_str(name: &str) -> Result { - Ok(match name.to_uppercase().as_str() { - "FIRST_VALUE" => BuiltInWindowFunction::FirstValue, - "LAST_VALUE" => BuiltInWindowFunction::LastValue, - "NTH_VALUE" => BuiltInWindowFunction::NthValue, - _ => return plan_err!("There is no built-in window function named {name}"), - }) - } -} - -/// Returns the datatype of the built-in window function -impl BuiltInWindowFunction { - pub fn return_type(&self, input_expr_types: &[DataType]) -> Result { - // Note that this function *must* return the same type that the respective physical expression returns - // or the execution panics. - - // Verify that this is a valid set of data types for this function - data_types(input_expr_types, &self.signature()) - // Original errors are all related to wrong function signature - // Aggregate them for better error message - .map_err(|_| { - plan_datafusion_err!( - "{}", - utils::generate_signature_error_msg( - &format!("{self}"), - self.signature(), - input_expr_types, - ) - ) - })?; - - match self { - BuiltInWindowFunction::FirstValue - | BuiltInWindowFunction::LastValue - | BuiltInWindowFunction::NthValue => Ok(input_expr_types[0].clone()), - } - } - - /// The signatures supported by the built-in window function `fun`. - pub fn signature(&self) -> Signature { - // Note: The physical expression must accept the type returned by this function or the execution panics. - match self { - BuiltInWindowFunction::FirstValue | BuiltInWindowFunction::LastValue => { - Signature::any(1, Volatility::Immutable) - } - BuiltInWindowFunction::NthValue => Signature::any(2, Volatility::Immutable), - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - use strum::IntoEnumIterator; - #[test] - // Test for BuiltInWindowFunction's Display and from_str() implementations. - // For each variant in BuiltInWindowFunction, it converts the variant to a string - // and then back to a variant. The test asserts that the original variant and - // the reconstructed variant are the same. This assertion is also necessary for - // function suggestion. See https://github.com/apache/datafusion/issues/8082 - fn test_display_and_from_str() { - for func_original in BuiltInWindowFunction::iter() { - let func_name = func_original.to_string(); - let func_from_str = BuiltInWindowFunction::from_str(&func_name).unwrap(); - assert_eq!(func_from_str, func_original); - } - } -} diff --git a/datafusion/expr/src/expr.rs b/datafusion/expr/src/expr.rs index 4042d7888b64..83d35c3d25b1 100644 --- a/datafusion/expr/src/expr.rs +++ b/datafusion/expr/src/expr.rs @@ -27,10 +27,7 @@ use crate::expr_fn::binary_expr; use crate::logical_plan::Subquery; use crate::utils::expr_to_columns; use crate::Volatility; -use crate::{ - udaf, BuiltInWindowFunction, ExprSchemable, Operator, Signature, WindowFrame, - WindowUDF, -}; +use crate::{udaf, ExprSchemable, Operator, Signature, WindowFrame, WindowUDF}; use arrow::datatypes::{DataType, FieldRef}; use datafusion_common::cse::HashNode; @@ -697,13 +694,13 @@ impl AggregateFunction { } } -/// WindowFunction +/// A function used as a SQL window function +/// +/// In SQL, you can use: +/// - Actual window functions ([`WindowUDF`]) +/// - Normal aggregate functions ([`AggregateUDF`]) #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)] -/// Defines which implementation of an aggregate function DataFusion should call. pub enum WindowFunctionDefinition { - /// A built in aggregate function that leverages an aggregate function - /// A a built-in window function - BuiltInWindowFunction(BuiltInWindowFunction), /// A user defined aggregate function AggregateUDF(Arc), /// A user defined aggregate function @@ -719,9 +716,6 @@ impl WindowFunctionDefinition { display_name: &str, ) -> Result { match self { - WindowFunctionDefinition::BuiltInWindowFunction(fun) => { - fun.return_type(input_expr_types) - } WindowFunctionDefinition::AggregateUDF(fun) => { fun.return_type(input_expr_types) } @@ -734,7 +728,6 @@ impl WindowFunctionDefinition { /// The signatures supported by the function `fun`. pub fn signature(&self) -> Signature { match self { - WindowFunctionDefinition::BuiltInWindowFunction(fun) => fun.signature(), WindowFunctionDefinition::AggregateUDF(fun) => fun.signature().clone(), WindowFunctionDefinition::WindowUDF(fun) => fun.signature().clone(), } @@ -743,7 +736,6 @@ impl WindowFunctionDefinition { /// Function's name for display pub fn name(&self) -> &str { match self { - WindowFunctionDefinition::BuiltInWindowFunction(fun) => fun.name(), WindowFunctionDefinition::WindowUDF(fun) => fun.name(), WindowFunctionDefinition::AggregateUDF(fun) => fun.name(), } @@ -753,19 +745,12 @@ impl WindowFunctionDefinition { impl Display for WindowFunctionDefinition { fn fmt(&self, f: &mut Formatter) -> fmt::Result { match self { - WindowFunctionDefinition::BuiltInWindowFunction(fun) => Display::fmt(fun, f), WindowFunctionDefinition::AggregateUDF(fun) => Display::fmt(fun, f), WindowFunctionDefinition::WindowUDF(fun) => Display::fmt(fun, f), } } } -impl From for WindowFunctionDefinition { - fn from(value: BuiltInWindowFunction) -> Self { - Self::BuiltInWindowFunction(value) - } -} - impl From> for WindowFunctionDefinition { fn from(value: Arc) -> Self { Self::AggregateUDF(value) @@ -780,26 +765,16 @@ impl From> for WindowFunctionDefinition { /// Window function /// -/// Holds the actual actual function to call [`WindowFunction`] as well as its +/// Holds the actual function to call [`WindowFunction`] as well as its /// arguments (`args`) and the contents of the `OVER` clause: /// /// 1. `PARTITION BY` /// 2. `ORDER BY` /// 3. Window frame (e.g. `ROWS 1 PRECEDING AND 1 FOLLOWING`) /// -/// # Example -/// ``` -/// # use datafusion_expr::{Expr, BuiltInWindowFunction, col, ExprFunctionExt}; -/// # use datafusion_expr::expr::WindowFunction; -/// // Create FIRST_VALUE(a) OVER (PARTITION BY b ORDER BY c) -/// let expr = Expr::WindowFunction( -/// WindowFunction::new(BuiltInWindowFunction::FirstValue, vec![col("a")]) -/// ) -/// .partition_by(vec![col("b")]) -/// .order_by(vec![col("b").sort(true, true)]) -/// .build() -/// .unwrap(); -/// ``` +/// See [`ExprFunctionExt`] for examples of how to create a `WindowFunction`. +/// +/// [`ExprFunctionExt`]: crate::ExprFunctionExt #[derive(Clone, PartialEq, Eq, PartialOrd, Hash, Debug)] pub struct WindowFunction { /// Name of the function diff --git a/datafusion/expr/src/expr_schema.rs b/datafusion/expr/src/expr_schema.rs index 2225f457f626..b1a461eca41d 100644 --- a/datafusion/expr/src/expr_schema.rs +++ b/datafusion/expr/src/expr_schema.rs @@ -481,12 +481,6 @@ impl Expr { .map(|e| e.get_type(schema)) .collect::>>()?; match fun { - WindowFunctionDefinition::BuiltInWindowFunction(window_fun) => { - let return_type = window_fun.return_type(&data_types)?; - let nullable = - !["RANK", "NTILE", "CUME_DIST"].contains(&window_fun.name()); - Ok((return_type, nullable)) - } WindowFunctionDefinition::AggregateUDF(udaf) => { let new_types = data_types_with_aggregate_udf(&data_types, udaf) .map_err(|err| { diff --git a/datafusion/expr/src/lib.rs b/datafusion/expr/src/lib.rs index 3faa8192f3eb..27b2d71b1f42 100644 --- a/datafusion/expr/src/lib.rs +++ b/datafusion/expr/src/lib.rs @@ -28,7 +28,6 @@ //! //! The [expr_fn] module contains functions for creating expressions. -mod built_in_window_function; mod literal; mod operation; mod partition_evaluator; @@ -67,7 +66,6 @@ pub mod var_provider; pub mod window_frame; pub mod window_state; -pub use built_in_window_function::BuiltInWindowFunction; pub use datafusion_expr_common::accumulator::Accumulator; pub use datafusion_expr_common::columnar_value::ColumnarValue; pub use datafusion_expr_common::groups_accumulator::{EmitTo, GroupsAccumulator}; diff --git a/datafusion/expr/src/udwf.rs b/datafusion/expr/src/udwf.rs index 124625280670..475b864a8a18 100644 --- a/datafusion/expr/src/udwf.rs +++ b/datafusion/expr/src/udwf.rs @@ -39,8 +39,16 @@ use datafusion_functions_window_common::field::WindowUDFFieldArgs; use datafusion_functions_window_common::partition::PartitionEvaluatorArgs; use datafusion_physical_expr_common::physical_expr::PhysicalExpr; -/// Logical representation of a user-defined window function (UDWF) -/// A UDWF is different from a UDF in that it is stateful across batches. +/// Logical representation of a user-defined window function (UDWF). +/// +/// A Window Function is called via the SQL `OVER` clause: +/// +/// ```sql +/// SELECT first_value(col) OVER (PARTITION BY a, b ORDER BY c) FROM foo; +/// ``` +/// +/// A UDWF is different from a user defined function (UDF) in that it is +/// stateful across batches. /// /// See the documentation on [`PartitionEvaluator`] for more details /// diff --git a/datafusion/physical-plan/src/windows/mod.rs b/datafusion/physical-plan/src/windows/mod.rs index d2eb14638c71..a323a958cc76 100644 --- a/datafusion/physical-plan/src/windows/mod.rs +++ b/datafusion/physical-plan/src/windows/mod.rs @@ -103,9 +103,6 @@ pub fn create_window_expr( ignore_nulls: bool, ) -> Result> { Ok(match fun { - WindowFunctionDefinition::BuiltInWindowFunction(_fun) => { - unreachable!() - } WindowFunctionDefinition::AggregateUDF(fun) => { let aggregate = AggregateExprBuilder::new(Arc::clone(fun), args.to_vec()) .schema(Arc::new(input_schema.clone())) @@ -120,7 +117,6 @@ pub fn create_window_expr( aggregate, ) } - // TODO: Ordering not supported for Window UDFs yet WindowFunctionDefinition::WindowUDF(fun) => Arc::new(BuiltInWindowExpr::new( create_udwf_window_expr(fun, args, input_schema, name, ignore_nulls)?, partition_by, diff --git a/datafusion/proto/proto/datafusion.proto b/datafusion/proto/proto/datafusion.proto index 998c172f6ef4..6606b1e93f02 100644 --- a/datafusion/proto/proto/datafusion.proto +++ b/datafusion/proto/proto/datafusion.proto @@ -507,24 +507,9 @@ message ScalarUDFExprNode { optional bytes fun_definition = 3; } -enum BuiltInWindowFunction { - UNSPECIFIED = 0; // https://protobuf.dev/programming-guides/dos-donts/#unspecified-enum - // ROW_NUMBER = 0; - // RANK = 1; - // DENSE_RANK = 2; - // PERCENT_RANK = 3; - // CUME_DIST = 4; - // NTILE = 5; - // LAG = 6; - // LEAD = 7; - // FIRST_VALUE = 8; - // LAST_VALUE = 9; - // NTH_VALUE = 10; -} - message WindowExprNode { oneof window_function { - BuiltInWindowFunction built_in_function = 2; + // BuiltInWindowFunction built_in_function = 2; string udaf = 3; string udwf = 9; } @@ -866,7 +851,7 @@ message PhysicalAggregateExprNode { message PhysicalWindowExprNode { oneof window_function { - BuiltInWindowFunction built_in_function = 2; + // BuiltInWindowFunction built_in_function = 2; string user_defined_aggr_function = 3; } repeated PhysicalExprNode args = 4; diff --git a/datafusion/proto/src/generated/pbjson.rs b/datafusion/proto/src/generated/pbjson.rs index b5447ad6f473..09c873b1f98a 100644 --- a/datafusion/proto/src/generated/pbjson.rs +++ b/datafusion/proto/src/generated/pbjson.rs @@ -1654,74 +1654,6 @@ impl<'de> serde::Deserialize<'de> for BinaryExprNode { deserializer.deserialize_struct("datafusion.BinaryExprNode", FIELDS, GeneratedVisitor) } } -impl serde::Serialize for BuiltInWindowFunction { - #[allow(deprecated)] - fn serialize(&self, serializer: S) -> std::result::Result - where - S: serde::Serializer, - { - let variant = match self { - Self::Unspecified => "UNSPECIFIED", - }; - serializer.serialize_str(variant) - } -} -impl<'de> serde::Deserialize<'de> for BuiltInWindowFunction { - #[allow(deprecated)] - fn deserialize(deserializer: D) -> std::result::Result - where - D: serde::Deserializer<'de>, - { - const FIELDS: &[&str] = &[ - "UNSPECIFIED", - ]; - - struct GeneratedVisitor; - - impl<'de> serde::de::Visitor<'de> for GeneratedVisitor { - type Value = BuiltInWindowFunction; - - fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(formatter, "expected one of: {:?}", &FIELDS) - } - - fn visit_i64(self, v: i64) -> std::result::Result - where - E: serde::de::Error, - { - i32::try_from(v) - .ok() - .and_then(|x| x.try_into().ok()) - .ok_or_else(|| { - serde::de::Error::invalid_value(serde::de::Unexpected::Signed(v), &self) - }) - } - - fn visit_u64(self, v: u64) -> std::result::Result - where - E: serde::de::Error, - { - i32::try_from(v) - .ok() - .and_then(|x| x.try_into().ok()) - .ok_or_else(|| { - serde::de::Error::invalid_value(serde::de::Unexpected::Unsigned(v), &self) - }) - } - - fn visit_str(self, value: &str) -> std::result::Result - where - E: serde::de::Error, - { - match value { - "UNSPECIFIED" => Ok(BuiltInWindowFunction::Unspecified), - _ => Err(serde::de::Error::unknown_variant(value, FIELDS)), - } - } - } - deserializer.deserialize_any(GeneratedVisitor) - } -} impl serde::Serialize for CaseNode { #[allow(deprecated)] fn serialize(&self, serializer: S) -> std::result::Result @@ -16391,11 +16323,6 @@ impl serde::Serialize for PhysicalWindowExprNode { } if let Some(v) = self.window_function.as_ref() { match v { - physical_window_expr_node::WindowFunction::BuiltInFunction(v) => { - let v = BuiltInWindowFunction::try_from(*v) - .map_err(|_| serde::ser::Error::custom(format!("Invalid variant {}", *v)))?; - struct_ser.serialize_field("builtInFunction", &v)?; - } physical_window_expr_node::WindowFunction::UserDefinedAggrFunction(v) => { struct_ser.serialize_field("userDefinedAggrFunction", v)?; } @@ -16421,8 +16348,6 @@ impl<'de> serde::Deserialize<'de> for PhysicalWindowExprNode { "name", "fun_definition", "funDefinition", - "built_in_function", - "builtInFunction", "user_defined_aggr_function", "userDefinedAggrFunction", ]; @@ -16435,7 +16360,6 @@ impl<'de> serde::Deserialize<'de> for PhysicalWindowExprNode { WindowFrame, Name, FunDefinition, - BuiltInFunction, UserDefinedAggrFunction, } impl<'de> serde::Deserialize<'de> for GeneratedField { @@ -16464,7 +16388,6 @@ impl<'de> serde::Deserialize<'de> for PhysicalWindowExprNode { "windowFrame" | "window_frame" => Ok(GeneratedField::WindowFrame), "name" => Ok(GeneratedField::Name), "funDefinition" | "fun_definition" => Ok(GeneratedField::FunDefinition), - "builtInFunction" | "built_in_function" => Ok(GeneratedField::BuiltInFunction), "userDefinedAggrFunction" | "user_defined_aggr_function" => Ok(GeneratedField::UserDefinedAggrFunction), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), } @@ -16532,12 +16455,6 @@ impl<'de> serde::Deserialize<'de> for PhysicalWindowExprNode { map_.next_value::<::std::option::Option<::pbjson::private::BytesDeserialize<_>>>()?.map(|x| x.0) ; } - GeneratedField::BuiltInFunction => { - if window_function__.is_some() { - return Err(serde::de::Error::duplicate_field("builtInFunction")); - } - window_function__ = map_.next_value::<::std::option::Option>()?.map(|x| physical_window_expr_node::WindowFunction::BuiltInFunction(x as i32)); - } GeneratedField::UserDefinedAggrFunction => { if window_function__.is_some() { return Err(serde::de::Error::duplicate_field("userDefinedAggrFunction")); @@ -21475,11 +21392,6 @@ impl serde::Serialize for WindowExprNode { } if let Some(v) = self.window_function.as_ref() { match v { - window_expr_node::WindowFunction::BuiltInFunction(v) => { - let v = BuiltInWindowFunction::try_from(*v) - .map_err(|_| serde::ser::Error::custom(format!("Invalid variant {}", *v)))?; - struct_ser.serialize_field("builtInFunction", &v)?; - } window_expr_node::WindowFunction::Udaf(v) => { struct_ser.serialize_field("udaf", v)?; } @@ -21507,8 +21419,6 @@ impl<'de> serde::Deserialize<'de> for WindowExprNode { "windowFrame", "fun_definition", "funDefinition", - "built_in_function", - "builtInFunction", "udaf", "udwf", ]; @@ -21520,7 +21430,6 @@ impl<'de> serde::Deserialize<'de> for WindowExprNode { OrderBy, WindowFrame, FunDefinition, - BuiltInFunction, Udaf, Udwf, } @@ -21549,7 +21458,6 @@ impl<'de> serde::Deserialize<'de> for WindowExprNode { "orderBy" | "order_by" => Ok(GeneratedField::OrderBy), "windowFrame" | "window_frame" => Ok(GeneratedField::WindowFrame), "funDefinition" | "fun_definition" => Ok(GeneratedField::FunDefinition), - "builtInFunction" | "built_in_function" => Ok(GeneratedField::BuiltInFunction), "udaf" => Ok(GeneratedField::Udaf), "udwf" => Ok(GeneratedField::Udwf), _ => Err(serde::de::Error::unknown_field(value, FIELDS)), @@ -21611,12 +21519,6 @@ impl<'de> serde::Deserialize<'de> for WindowExprNode { map_.next_value::<::std::option::Option<::pbjson::private::BytesDeserialize<_>>>()?.map(|x| x.0) ; } - GeneratedField::BuiltInFunction => { - if window_function__.is_some() { - return Err(serde::de::Error::duplicate_field("builtInFunction")); - } - window_function__ = map_.next_value::<::std::option::Option>()?.map(|x| window_expr_node::WindowFunction::BuiltInFunction(x as i32)); - } GeneratedField::Udaf => { if window_function__.is_some() { return Err(serde::de::Error::duplicate_field("udaf")); diff --git a/datafusion/proto/src/generated/prost.rs b/datafusion/proto/src/generated/prost.rs index 40bc8bd9eaf5..ad5320fc657c 100644 --- a/datafusion/proto/src/generated/prost.rs +++ b/datafusion/proto/src/generated/prost.rs @@ -742,15 +742,14 @@ pub struct WindowExprNode { pub window_frame: ::core::option::Option, #[prost(bytes = "vec", optional, tag = "10")] pub fun_definition: ::core::option::Option<::prost::alloc::vec::Vec>, - #[prost(oneof = "window_expr_node::WindowFunction", tags = "2, 3, 9")] + #[prost(oneof = "window_expr_node::WindowFunction", tags = "3, 9")] pub window_function: ::core::option::Option, } /// Nested message and enum types in `WindowExprNode`. pub mod window_expr_node { #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum WindowFunction { - #[prost(enumeration = "super::BuiltInWindowFunction", tag = "2")] - BuiltInFunction(i32), + /// BuiltInWindowFunction built_in_function = 2; #[prost(string, tag = "3")] Udaf(::prost::alloc::string::String), #[prost(string, tag = "9")] @@ -1267,7 +1266,7 @@ pub struct PhysicalWindowExprNode { pub name: ::prost::alloc::string::String, #[prost(bytes = "vec", optional, tag = "9")] pub fun_definition: ::core::option::Option<::prost::alloc::vec::Vec>, - #[prost(oneof = "physical_window_expr_node::WindowFunction", tags = "2, 3")] + #[prost(oneof = "physical_window_expr_node::WindowFunction", tags = "3")] pub window_function: ::core::option::Option< physical_window_expr_node::WindowFunction, >, @@ -1276,8 +1275,7 @@ pub struct PhysicalWindowExprNode { pub mod physical_window_expr_node { #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum WindowFunction { - #[prost(enumeration = "super::BuiltInWindowFunction", tag = "2")] - BuiltInFunction(i32), + /// BuiltInWindowFunction built_in_function = 2; #[prost(string, tag = "3")] UserDefinedAggrFunction(::prost::alloc::string::String), } @@ -1837,30 +1835,6 @@ pub struct CteWorkTableScanNode { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[repr(i32)] -pub enum BuiltInWindowFunction { - /// - Unspecified = 0, -} -impl BuiltInWindowFunction { - /// String value of the enum field names used in the ProtoBuf definition. - /// - /// The values are not transformed in any way and thus are considered stable - /// (if the ProtoBuf definition does not change) and safe for programmatic use. - pub fn as_str_name(&self) -> &'static str { - match self { - Self::Unspecified => "UNSPECIFIED", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "UNSPECIFIED" => Some(Self::Unspecified), - _ => None, - } - } -} -#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] -#[repr(i32)] pub enum WindowFrameUnits { Rows = 0, Range = 1, diff --git a/datafusion/proto/src/logical_plan/from_proto.rs b/datafusion/proto/src/logical_plan/from_proto.rs index 4708e49d4565..301efc42a7c4 100644 --- a/datafusion/proto/src/logical_plan/from_proto.rs +++ b/datafusion/proto/src/logical_plan/from_proto.rs @@ -28,7 +28,7 @@ use datafusion_expr::ExprFunctionExt; use datafusion_expr::{ expr::{self, InList, WindowFunction}, logical_plan::{PlanType, StringifiedPlan}, - Between, BinaryExpr, BuiltInWindowFunction, Case, Cast, Expr, GroupingSet, + Between, BinaryExpr, Case, Cast, Expr, GroupingSet, GroupingSet::GroupingSets, JoinConstraint, JoinType, Like, Operator, TryCast, WindowFrame, WindowFrameBound, WindowFrameUnits, @@ -148,14 +148,6 @@ impl From<&protobuf::StringifiedPlan> for StringifiedPlan { } } -impl From for BuiltInWindowFunction { - fn from(built_in_function: protobuf::BuiltInWindowFunction) -> Self { - match built_in_function { - protobuf::BuiltInWindowFunction::Unspecified => todo!(), - } - } -} - impl TryFrom for WindowFrame { type Error = Error; @@ -285,25 +277,6 @@ pub fn parse_expr( // TODO: support proto for null treatment match window_function { - window_expr_node::WindowFunction::BuiltInFunction(i) => { - let built_in_function = protobuf::BuiltInWindowFunction::try_from(*i) - .map_err(|_| Error::unknown("BuiltInWindowFunction", *i))? - .into(); - - let args = parse_exprs(&expr.exprs, registry, codec)?; - - Expr::WindowFunction(WindowFunction::new( - expr::WindowFunctionDefinition::BuiltInWindowFunction( - built_in_function, - ), - args, - )) - .partition_by(partition_by) - .order_by(order_by) - .window_frame(window_frame) - .build() - .map_err(Error::DataFusionError) - } window_expr_node::WindowFunction::Udaf(udaf_name) => { let udaf_function = match &expr.fun_definition { Some(buf) => codec.try_decode_udaf(udaf_name, buf)?, diff --git a/datafusion/proto/src/logical_plan/to_proto.rs b/datafusion/proto/src/logical_plan/to_proto.rs index 5ef64675280e..caceb3db164c 100644 --- a/datafusion/proto/src/logical_plan/to_proto.rs +++ b/datafusion/proto/src/logical_plan/to_proto.rs @@ -306,7 +306,6 @@ pub fn serialize_expr( null_treatment: _, }) => { let (window_function, fun_definition) = match fun { - WindowFunctionDefinition::BuiltInWindowFunction(_fun) => unreachable!(), WindowFunctionDefinition::AggregateUDF(aggr_udf) => { let mut buf = Vec::new(); let _ = codec.try_encode_udaf(aggr_udf, &mut buf); diff --git a/datafusion/proto/src/physical_plan/from_proto.rs b/datafusion/proto/src/physical_plan/from_proto.rs index 31b59c2a9457..1c5bdd0c02ba 100644 --- a/datafusion/proto/src/physical_plan/from_proto.rs +++ b/datafusion/proto/src/physical_plan/from_proto.rs @@ -146,15 +146,6 @@ pub fn parse_physical_window_expr( let fun = if let Some(window_func) = proto.window_function.as_ref() { match window_func { - protobuf::physical_window_expr_node::WindowFunction::BuiltInFunction(n) => { - let f = protobuf::BuiltInWindowFunction::try_from(*n).map_err(|_| { - proto_error(format!( - "Received an unknown window builtin function: {n}" - )) - })?; - - WindowFunctionDefinition::BuiltInWindowFunction(f.into()) - } protobuf::physical_window_expr_node::WindowFunction::UserDefinedAggrFunction(udaf_name) => { WindowFunctionDefinition::AggregateUDF(match &proto.fun_definition { Some(buf) => codec.try_decode_udaf(udaf_name, buf)?,