haohuaijin commented on code in PR #8382:
URL: https://github.com/apache/arrow-datafusion/pull/8382#discussion_r1418329021
##########
datafusion/expr/src/expr.rs:
##########
@@ -393,6 +398,258 @@ impl ScalarFunction {
}
}
+/// WindowFunction
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
+pub enum WindowFunctionDefinition {
+ /// A built in aggregate function that leverages an aggregate function
+ AggregateFunction(aggregate_function::AggregateFunction),
+ /// A a built-in window function
+ BuiltInWindowFunction(BuiltInWindowFunction),
+ /// A user defined aggregate function
+ AggregateUDF(Arc<udaf::AggregateUDF>),
+ /// A user defined aggregate function
+ WindowUDF(Arc<WindowUDF>),
+}
+
+/// Find DataFusion's built-in window function by name.
+pub fn find_df_window_func(name: &str) -> Option<WindowFunctionDefinition> {
+ let name = name.to_lowercase();
+ // Code paths for window functions leveraging ordinary aggregators and
+ // built-in window functions are quite different, and the same function
+ // may have different implementations for these cases. If the sought
+ // function is not found among built-in window functions, we search for
+ // it among aggregate functions.
+ if let Ok(built_in_function) =
BuiltInWindowFunction::from_str(name.as_str()) {
+ Some(WindowFunctionDefinition::BuiltInWindowFunction(
+ built_in_function,
+ ))
+ } else if let Ok(aggregate) =
+ aggregate_function::AggregateFunction::from_str(name.as_str())
+ {
+ Some(WindowFunctionDefinition::AggregateFunction(aggregate))
+ } else {
+ None
+ }
+}
+
+impl fmt::Display for BuiltInWindowFunction {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ write!(f, "{}", self.name())
+ }
+}
+
+impl fmt::Display for WindowFunctionDefinition {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ match self {
+ WindowFunctionDefinition::AggregateFunction(fun) => fun.fmt(f),
+ WindowFunctionDefinition::BuiltInWindowFunction(fun) => fun.fmt(f),
+ WindowFunctionDefinition::AggregateUDF(fun) =>
std::fmt::Debug::fmt(fun, f),
+ WindowFunctionDefinition::WindowUDF(fun) => fun.fmt(f),
+ }
+ }
+}
+
+/// A [window function] built in to DataFusion
+///
+/// [window function]: https://en.wikipedia.org/wiki/Window_function_(SQL)
+#[derive(Debug, Clone, PartialEq, Eq, Hash, EnumIter)]
+pub enum BuiltInWindowFunction {
Review Comment:
> * `BuiltinWindowFunction` goes into
`datafusion/expr/src/built_in_window_function.rs`
> * `WindowFunction` becomes `WindowFunctionDefinition` and goes into
`datafusion/expr/src/expr.rs` with its trait implementations
yes, you are correct.
> * public functions in `window_function` stays there
maybe those public functions also can move to
`datafusion/expr/src/built_in_window_function.rs`. cc @alamb
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]