WIP on StreamItem unified top-level type, at least it compiles

This commit is contained in:
Dominik Werder
2021-05-20 15:39:24 +02:00
parent 72006fbf17
commit 49af7ce561
7 changed files with 394 additions and 139 deletions

View File

@@ -38,13 +38,14 @@ pub trait IntoBinnedT {
fn into_binned_t(self, spec: BinnedRange) -> Self::StreamOut;
}
impl<T, I> IntoBinnedT for T
impl<S, I> IntoBinnedT for S
where
S: Stream<Item = Result<I, Error>> + Unpin,
I: AggregatableTdim + Unpin,
T: Stream<Item = Result<I, Error>> + Unpin,
//I: AggregatableTdim,
I::Aggregator: Unpin,
{
type StreamOut = IntoBinnedTDefaultStream<T, I>;
type StreamOut = IntoBinnedTDefaultStream<S, I>;
fn into_binned_t(self, spec: BinnedRange) -> Self::StreamOut {
IntoBinnedTDefaultStream::new(self, spec)
@@ -53,8 +54,8 @@ where
pub struct IntoBinnedTDefaultStream<S, I>
where
I: AggregatableTdim,
S: Stream<Item = Result<I, Error>>,
I: AggregatableTdim,
{
inp: S,
aggtor: Option<I::Aggregator>,
@@ -72,8 +73,8 @@ where
impl<S, I> IntoBinnedTDefaultStream<S, I>
where
I: AggregatableTdim,
S: Stream<Item = Result<I, Error>> + Unpin,
I: AggregatableTdim,
{
pub fn new(inp: S, spec: BinnedRange) -> Self {
let range = spec.get_range(0);
@@ -200,20 +201,15 @@ where
impl<S, I> Stream for IntoBinnedTDefaultStream<S, I>
where
I: AggregatableTdim + Unpin,
S: Stream<Item = Result<I, Error>> + Unpin,
//I: AggregatableTdim,
I: AggregatableTdim + Unpin,
I::Aggregator: Unpin,
{
type Item = Result<<I::Aggregator as AggregatorTdim>::OutputValue, Error>;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
use Poll::*;
/*
Reconsider structure here:
I want to exhaust the input stream until it gives Ready(None) because there can be more Status or other new events.
The first time that I recognize that the requested data range is complete, I can set a flag.
After that, I can dismiss incoming data events.
*/
'outer: loop {
break if self.completed {
panic!("IntoBinnedTDefaultStream poll_next on completed");

View File

@@ -1,3 +1,5 @@
use crate::agg::binnedt::{AggregatableTdim, AggregatorTdim};
use crate::agg::AggregatableXdim1Bin;
use crate::streamlog::LogItem;
use err::Error;
use netpod::EventDataReadStats;
@@ -33,3 +35,145 @@ pub trait ToJsonResult {
type Output;
fn to_json_result(&self) -> Result<Self::Output, Error>;
}
impl<T> AggregatableXdim1Bin for StreamItem<T>
where
// TODO bound on the Output ???
//T: AggregatableTdim + AggregatableXdim1Bin<Output = T>,
T: AggregatableTdim + AggregatableXdim1Bin,
{
type Output = StreamItem<<T as AggregatableXdim1Bin>::Output>;
fn into_agg(self) -> Self::Output {
// TODO how to handle the type mismatch?
/*match self {
Self::Log(item) => Self::Log(item),
Self::Stats(item) => Self::Stats(item),
Self::DataItem(item) => Self::DataItem(item.into_agg()),
}*/
err::todoval()
}
}
pub struct StreamItemAggregator<T>
where
T: AggregatableTdim,
{
inner_agg: <T as AggregatableTdim>::Aggregator,
_mark: std::marker::PhantomData<T>,
}
impl<T> StreamItemAggregator<T>
where
T: AggregatableTdim,
{
pub fn new(ts1: u64, ts2: u64) -> Self {
Self {
inner_agg: <T as AggregatableTdim>::aggregator_new_static(ts1, ts2),
_mark: std::marker::PhantomData::default(),
}
}
}
impl<T> AggregatorTdim for StreamItemAggregator<T>
where
T: AggregatableTdim,
{
type InputValue = StreamItem<T>;
type OutputValue = StreamItem<<<T as AggregatableTdim>::Aggregator as AggregatorTdim>::OutputValue>;
fn ends_before(&self, inp: &Self::InputValue) -> bool {
todo!()
}
fn ends_after(&self, inp: &Self::InputValue) -> bool {
todo!()
}
fn starts_after(&self, inp: &Self::InputValue) -> bool {
todo!()
}
fn ingest(&mut self, inp: &mut Self::InputValue) {
todo!()
}
fn result(self) -> Vec<Self::OutputValue> {
todo!()
}
}
impl<T> AggregatableTdim for StreamItem<T>
where
T: AggregatableTdim,
{
type Output = StreamItem<<StreamItemAggregator<T> as AggregatorTdim>::OutputValue>;
type Aggregator = StreamItemAggregator<T>;
fn aggregator_new_static(ts1: u64, ts2: u64) -> Self::Aggregator {
Self::Aggregator::new(ts1, ts2)
}
fn is_range_complete(&self) -> bool {
match self {
Self::DataItem(item) => item.is_range_complete(),
Self::Log(_) => false,
Self::Stats(_) => false,
}
}
// TODO refactor: is this necessary to have on the trait?
fn make_range_complete_item() -> Option<Self> {
match <T as AggregatableTdim>::make_range_complete_item() {
Some(k) => Some(Self::DataItem(k)),
None => None,
}
}
// TODO refactor: the point of having the StreamItem is that this function is no longer necessary:
fn is_log_item(&self) -> bool {
if let Self::Log(_) = self {
true
} else {
false
}
}
// TODO should be able to remove this from trait:
fn log_item(self) -> Option<LogItem> {
if let Self::Log(item) = self {
Some(item)
} else {
None
}
}
// TODO should be able to remove this from trait:
fn make_log_item(item: LogItem) -> Option<Self> {
Some(Self::Log(item))
}
// TODO should be able to remove this from trait:
fn is_stats_item(&self) -> bool {
if let Self::Stats(_) = self {
true
} else {
false
}
}
// TODO should be able to remove this from trait:
fn stats_item(self) -> Option<EventDataReadStats> {
if let Self::Stats(_item) = self {
// TODO this whole function should no longer be needed.
Some(err::todoval())
} else {
None
}
}
// TODO should be able to remove this from trait:
fn make_stats_item(item: EventDataReadStats) -> Option<Self> {
Some(Self::Stats(StatsItem::EventDataReadStats(item)))
}
}