pub struct GroupSpec { /* private fields */ }Expand description
Groups of rows with equal key values, and aggregates over each group.
use std::sync::Arc;
use arrow_array::{ArrayRef, Decimal128Array, Int64Array, RecordBatch, StringArray};
use densa_data::{Aggregate, GroupSpec, LiveTable};
let trades = |ids: Vec<i64>, desks: Vec<&str>, qty: Vec<i64>| {
RecordBatch::try_from_iter([
("id", Arc::new(Int64Array::from(ids)) as ArrayRef),
("desk", Arc::new(StringArray::from(desks)) as ArrayRef),
("qty", Arc::new(Int64Array::from(qty)) as ArrayRef),
])
};
let mut table = LiveTable::new(trades(vec![], vec![], vec![])?.schema(), "id")?;
let by_desk = table.add_groups(
GroupSpec::new()
.group_by("desk")
.aggregate(Aggregate::count())
.aggregate(Aggregate::sum("qty")),
)?;
table.upsert(trades(vec![1, 2, 3], vec!["fx", "rates", "fx"], vec![5, 7, 10])?)?;
table.upsert(trades(vec![3], vec!["rates"], vec![10])?)?; // trade 3 moves desk
let totals = table.groups(by_desk).unwrap().to_batch()?; // fx: 1 trade, rates: 2
let qty = totals.column(2).as_any().downcast_ref::<Decimal128Array>().unwrap();
assert_eq!((qty.value(0), qty.value(1)), (5, 17));Implementations§
Source§impl GroupSpec
impl GroupSpec
Sourcepub fn new() -> Self
pub fn new() -> Self
No keys and no aggregates yet. Without keys there is exactly one group, of every counted row, even when there are none.
Sourcepub fn group_by(self, column: impl Into<String>) -> Self
pub fn group_by(self, column: impl Into<String>) -> Self
Groups by column too, after the key columns given before it. Groups are listed by
key in the order views sort: ascending, nulls last. -0.0 and 0.0 are one key, and
so are all NaNs.
Trait Implementations§
impl StructuralPartialEq for GroupSpec
Auto Trait Implementations§
impl Freeze for GroupSpec
impl RefUnwindSafe for GroupSpec
impl Send for GroupSpec
impl Sync for GroupSpec
impl Unpin for GroupSpec
impl UnsafeUnpin for GroupSpec
impl UnwindSafe for GroupSpec
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more