Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
create_udwf_expr in datafusion::functions_window - Rust
[go: Go Back, main page]

Macro create_udwf_expr

Source
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 the Signature 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 is Expr. When omitted this creates a function with zero parameters.

§Example

  1. With Zero Parameters
use arrow::datatypes::FieldRef;

/// 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."
);
  1. With Multiple Parameters
use arrow::datatypes::FieldRef;
/// 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."
);