Updates and returns the in progress [`Expr::AggregateFunction`] or [`Expr::WindowFunction`] # Errors: Returns an error if this builder [`ExprFunctionExt`] was used with an `Expr` variant other than [`Expr::AggregateFunction`] or [`Expr::WindowFunction`]
(self)
| 839 | /// Returns an error if this builder [`ExprFunctionExt`] was used with an |
| 840 | /// `Expr` variant other than [`Expr::AggregateFunction`] or [`Expr::WindowFunction`] |
| 841 | pub fn build(self) -> Result<Expr> { |
| 842 | let Self { |
| 843 | fun, |
| 844 | order_by, |
| 845 | filter, |
| 846 | distinct, |
| 847 | null_treatment, |
| 848 | partition_by, |
| 849 | window_frame, |
| 850 | } = self; |
| 851 | |
| 852 | let Some(fun) = fun else { |
| 853 | return plan_err!( |
| 854 | "ExprFunctionExt can only be used with Expr::AggregateFunction or Expr::WindowFunction" |
| 855 | ); |
| 856 | }; |
| 857 | |
| 858 | let fun_expr = match fun { |
| 859 | ExprFuncKind::Aggregate(mut udaf) => { |
| 860 | udaf.params.order_by = order_by.unwrap_or_default(); |
| 861 | udaf.params.filter = filter.map(Box::new); |
| 862 | udaf.params.distinct = distinct; |
| 863 | udaf.params.null_treatment = null_treatment; |
| 864 | Expr::AggregateFunction(udaf) |
| 865 | } |
| 866 | ExprFuncKind::Window(mut udwf) => { |
| 867 | let has_order_by = order_by.as_ref().map(|o| !o.is_empty()); |
| 868 | udwf.params.partition_by = partition_by.unwrap_or_default(); |
| 869 | udwf.params.order_by = order_by.unwrap_or_default(); |
| 870 | udwf.params.window_frame = |
| 871 | window_frame.unwrap_or_else(|| WindowFrame::new(has_order_by)); |
| 872 | udwf.params.filter = filter.map(Box::new); |
| 873 | udwf.params.null_treatment = null_treatment; |
| 874 | udwf.params.distinct = distinct; |
| 875 | Expr::WindowFunction(udwf) |
| 876 | } |
| 877 | }; |
| 878 | |
| 879 | Ok(fun_expr) |
| 880 | } |
| 881 | } |
| 882 | |
| 883 | impl ExprFunctionExt for ExprFuncBuilder { |