/// This is the implementation of the `window_bounds` user defined
/// function used in IOx to compute window boundaries when doing
/// grouping by windows.
This is the implementation of the `window_bounds` user defined
function used in IOx to compute window boundaries when doing
grouping by windows.
This is the implementation of the ` window_bounds ` user defined function used in IOx to compute window boundaries when doing grouping by windows .
fn window_bounds(arg: &dyn Array, every: WindowDuration, offset: WindowDuration) -> ArrayRef {
    // `arg` and output are dynamically-typed Arrow arrays, which means that we
    // need to:
    //
    // 1. cast the values to the type we want
    // 2. perform the window_bounds calculation for every element in the
    //     timestamp array
    // 3. construct the resulting array
    let time = arg
        .as_any()
        .downcast_ref::<TimestampNanosecondArray>()
        .expect("cast of time failed");
    // Note: the Go code uses the `Stop` field of the `GetEarliestBounds` call as
    // the window boundary https://github.com/influxdata/influxdb/blob/master/storage/reads/array_cursor.gen.go#L546
    // Note window doesn't use the period argument
    let period = internal::Duration::from_nsecs(0);
    let window = internal::Window::new((&every).into(), period, (&offset).into());
    // calculate the output times, one at a time, one element at a time
    let values = time.iter().map(|ts| {
        ts.map(|ts| {
            let bounds = window.get_earliest_bounds(ts);
            bounds.stop
        })
    });
    let array = values.collect::<TimestampNanosecondArray>();
    Arc::new(array) as ArrayRef
}
fn window_bounds ( arg : & dyn Array , every : WindowDuration , offset : WindowDuration ) -> ArrayRef { // `arg` and output are dynamically-typed Arrow arrays, which means that we // need to: // // 1. cast the values to the type we want // 2. perform the window_bounds calculation for every element in the //     timestamp array // 3. construct the resulting array let time = arg . as_any ( ) . downcast_ref :: < TimestampNanosecondArray > ( ) . expect ( " " ) ; // Note: the Go code uses the `Stop` field of the `GetEarliestBounds` call as // the window boundary https://github.com/influxdata/influxdb/blob/master/storage/reads/array_cursor.gen.go#L546 // Note window doesn't use the period argument let period = internal :: Duration :: from_nsecs ( 0 ) ; let window = internal :: Window :: new ( ( & every ) . into ( ) , period , ( & offset ) . into ( ) ) ; // calculate the output times, one at a time, one element at a time let values = time . iter ( ) . map ( | ts | { ts . map ( | ts | { let bounds = window . get_earliest_bounds ( ts ) ; bounds . stop } ) } ) ; let array = values . collect :: < TimestampNanosecondArray > ( ) ; Arc :: new ( array ) as ArrayRef }
This is the implementation of the `window_bounds` user defined
function used in IOx to compute window boundaries when doing
grouping by windows.
This is the implementation of the ` window_bounds ` user defined function used in IOx to compute window boundaries when doing grouping by windows .
arg
&dyn Array
every
WindowDuration
offset
WindowDuration