macro_rules! create_udwf_expr { ($UDWF:ident, $OUT_FN_NAME:ident, $DOC:expr) => { ... }; ($UDWF:ident, $OUT_FN_NAME:ident, [$($PARAM:ident),+], $DOC:expr) => { ... }; }
Expand description
Create a WindowFunction
expression that exposes a fluent API
which you can use to build more complex expressions.
§Parameters
$UDWF
: The struct which defines theSignature
of the user-defined window function.$OUT_FN_NAME
: The basename to generate a unique function name like$OUT_FN_NAME_udwf
.$DOC
: Doc comments for UDWF.- (optional)
[$($PARAM:ident),+]
: An array of 1 or more parameters for the generated function. The type of parameters isExpr
. When omitted this creates a function with zero parameters.
§Example
- With Zero Parameters
/// Creates `row_number()` API which has zero parameters:
///
/// ```
/// /// Returns a unique row number for each row in window partition
/// /// beginning at 1.
/// pub fn row_number() -> datafusion_expr::Expr {
/// row_number_udwf().call(vec![])
/// }
/// ```
create_udwf_expr!(
RowNumber,
row_number,
"Returns a unique row number for each row in window partition beginning at 1."
);
- With Multiple Parameters
/// Creates `lead(expr, offset, default)` with 3 parameters:
///
/// ```
/// /// Returns a value evaluated at the row that is offset rows
/// /// after the current row within the partition.
/// pub fn lead(
/// expr: datafusion_expr::Expr,
/// offset: datafusion_expr::Expr,
/// default: datafusion_expr::Expr,
/// ) -> datafusion_expr::Expr {
/// lead_udwf().call(vec![expr, offset, default])
/// }
/// ```
create_udwf_expr!(
Lead,
lead,
[expr, offset, default],
"Returns a value evaluated at the row that is offset rows after the current row within the partition."
);