fn window_bounds_udf(args: &[ColumnarValue]) -> DataFusionResult<ColumnarValue> {
    assert_eq!(args.len(), 7);

    // extract the arguments as a Scalar
    macro_rules! extract_scalar {
        ($ARG:expr) => {
            match &args[$ARG] {
                ColumnarValue::Array(_) => {
                    return Err(DataFusionError::Internal(format!(
                        "window_bounds_udf argument {} not a scalar",
                        $ARG
                    )))
                }
                ColumnarValue::Scalar(v) => v.clone(),
            }
        };
    }

    let every: WindowDuration = EncodedWindowDuration {
        ty: extract_scalar!(1),
        field1: extract_scalar!(2),
        field2: extract_scalar!(3),
    }
    .try_into()?;

    let offset: WindowDuration = EncodedWindowDuration {
        ty: extract_scalar!(4),
        field1: extract_scalar!(5),
        field2: extract_scalar!(6),
    }
    .try_into()?;

    let arg = match &args[0] {
        ColumnarValue::Scalar(v) => {
            return Err(DataFusionError::NotImplemented(format!(
                "window_bounds against scalar arguments ({:?}) not yet implemented",
                v
            )))
        }
        ColumnarValue::Array(arr) => arr,
    };

    Ok(ColumnarValue::Array(window_bounds(arg, every, offset)))
}
/// Implement the window bounds function as a DataFusion UDF where
/// each of the two `WindowDuration` argument has been encoded as
/// three distinct arguments, for 7 total arguments
///
/// ```text
/// window_bounds(arg, every, offset)
/// ```
///
/// Becomes
///
/// ```text
/// window_bounds_udf(arg, every_type, every.field1, every.field2, offset_type, offset.field1, duration.field2)
/// ```
///
/// For example this would mean that `window_bounds` like this:
///
/// ```text
/// window_bounds(
///   col(time),
///   WindowDuration::Fixed(10),
///   WindowDuration::Variable(11, false)
/// )
/// ```
/// Would be called like:
///
/// ```text
/// window_bounds_udf(
///   col(time),
///   "fixed", 10, NULL,
///   "variable", 11, false
/// )
/// ```
///
/// Note: [`EncodedWindowDuration`] Handles the encoding / decoding of these arguments
Implement the window bounds function as a DataFusion UDF where
each of the two `WindowDuration` argument has been encoded as
three distinct arguments, for 7 total arguments



Becomes



For example this would mean that `window_bounds` like this.





[`EncodedWindowDuration`] Handles the encoding / decoding of these arguments
Implement the window bounds function as a DataFusion UDF where each of the two ` WindowDuration ` argument has been encoded as three distinct arguments for 7 total arguments Becomes For example this would mean that ` window_bounds ` like this . [ ` EncodedWindowDuration ` ] Handles the encoding / decoding of these arguments
fn window_bounds_udf(args: &[ColumnarValue]) -> DataFusionResult<ColumnarValue> {
    assert_eq!(args.len(), 7);
    // extract the arguments as a Scalar
    macro_rules! extract_scalar {
        ($ARG:expr) => {
            match &args[$ARG] {
                ColumnarValue::Array(_) => {
                    return Err(DataFusionError::Internal(format!(
                        "window_bounds_udf argument {} not a scalar",
                        $ARG
                    )))
                }
                ColumnarValue::Scalar(v) => v.clone(),
            }
        };
    }
    let every: WindowDuration = EncodedWindowDuration {
        ty: extract_scalar!(1),
        field1: extract_scalar!(2),
        field2: extract_scalar!(3),
    }
    .try_into()?;
    let offset: WindowDuration = EncodedWindowDuration {
        ty: extract_scalar!(4),
        field1: extract_scalar!(5),
        field2: extract_scalar!(6),
    }
    .try_into()?;
    let arg = match &args[0] {
        ColumnarValue::Scalar(v) => {
            return Err(DataFusionError::NotImplemented(format!(
                "window_bounds against scalar arguments ({:?}) not yet implemented",
                v
            )))
        }
        ColumnarValue::Array(arr) => arr,
    };
    Ok(ColumnarValue::Array(window_bounds(arg, every, offset)))
}
fn window_bounds_udf ( args : & [ ColumnarValue ] ) -> DataFusionResult < ColumnarValue > { assert_eq ! ( args len ( ) 7 ) ; // extract the arguments as a Scalar macro_rules! extract_scalar { ( $ARG : expr ) => { match args [ $ARG ] { ColumnarValue Array ( ) { return Err ( DataFusionError Internal ( format ( " " $ARG ) ) ) } ColumnarValue Scalar ( v ) v clone ( ) } } ; } let every : WindowDuration = EncodedWindowDuration { ty : extract_scalar ! ( 1 ) , field1 : extract_scalar ! ( 2 ) , field2 : extract_scalar ! ( 3 ) , } . try_into ( ) ? ; let offset : WindowDuration = EncodedWindowDuration { ty : extract_scalar ! ( 4 ) , field1 : extract_scalar ! ( 5 ) , field2 : extract_scalar ! ( 6 ) , } . try_into ( ) ? ; let arg = match & args [ 0 ] { ColumnarValue :: Scalar ( v ) => { return Err ( DataFusionError :: NotImplemented ( format ! ( " " v ) ) ) } ColumnarValue :: Array ( arr ) => arr , } ; Ok ( ColumnarValue :: Array ( window_bounds ( arg , every , offset ) ) ) }
Implement the window bounds function as a DataFusion UDF where
each of the two `WindowDuration` argument has been encoded as
three distinct arguments, for 7 total arguments
Implement the window bounds function as a DataFusion UDF where each of the two ` WindowDuration ` argument has been encoded as three distinct arguments for 7 total arguments
args
&[ColumnarValue]
args
&[ColumnarValue]