Remove unused merger
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
use crate::agg::eventbatch::{MinMaxAvgScalarEventBatch, MinMaxAvgScalarEventBatchStreamItem};
|
||||
use crate::agg::{Dim1F32Stream, Dim1F32StreamItem, ValuesDim1};
|
||||
use crate::eventchunker::EventChunkerItem;
|
||||
use crate::streamlog::LogItem;
|
||||
use err::Error;
|
||||
use futures_core::Stream;
|
||||
@@ -12,144 +10,6 @@ use std::task::{Context, Poll};
|
||||
#[allow(unused_imports)]
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
|
||||
pub struct MergeDim1F32Stream<S> {
|
||||
// yields Dim1F32StreamItem
|
||||
inps: Vec<Dim1F32Stream<S>>,
|
||||
current: Vec<CurVal>,
|
||||
ixs: Vec<usize>,
|
||||
errored: bool,
|
||||
completed: bool,
|
||||
batch: ValuesDim1,
|
||||
}
|
||||
|
||||
impl<S> MergeDim1F32Stream<S> {
|
||||
pub fn new(inps: Vec<Dim1F32Stream<S>>) -> Self {
|
||||
let n = inps.len();
|
||||
let mut current = vec![];
|
||||
for _ in 0..n {
|
||||
current.push(CurVal::None);
|
||||
}
|
||||
Self {
|
||||
inps,
|
||||
current: current,
|
||||
ixs: vec![0; n],
|
||||
batch: ValuesDim1::empty(),
|
||||
errored: false,
|
||||
completed: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Stream for MergeDim1F32Stream<S>
|
||||
where
|
||||
S: Stream<Item = Result<EventChunkerItem, Error>> + Unpin,
|
||||
{
|
||||
type Item = Result<Dim1F32StreamItem, Error>;
|
||||
|
||||
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Option<Self::Item>> {
|
||||
use Poll::*;
|
||||
// TODO rewrite making the break the default and explicit continue.
|
||||
'outer: loop {
|
||||
if self.completed {
|
||||
panic!("poll on complete stream");
|
||||
}
|
||||
if self.errored {
|
||||
self.completed = true;
|
||||
return Ready(None);
|
||||
}
|
||||
// can only run logic if all streams are either finished, errored or have some current value.
|
||||
for i1 in 0..self.inps.len() {
|
||||
match self.current[i1] {
|
||||
CurVal::None => {
|
||||
match self.inps[i1].poll_next_unpin(cx) {
|
||||
Ready(Some(Ok(k))) => {
|
||||
// TODO do I keep only the values as "current" or also the other kinds of items?
|
||||
// Can I process the other kinds instantly?
|
||||
match k {
|
||||
Dim1F32StreamItem::Values(vals) => {
|
||||
self.current[i1] = CurVal::Val(vals);
|
||||
}
|
||||
Dim1F32StreamItem::RangeComplete => {
|
||||
todo!();
|
||||
}
|
||||
Dim1F32StreamItem::EventDataReadStats(_stats) => {
|
||||
todo!();
|
||||
}
|
||||
}
|
||||
}
|
||||
Ready(Some(Err(e))) => {
|
||||
self.current[i1] = CurVal::Err(Error::with_msg(format!(
|
||||
"MergeDim1F32Stream error from upstream {:?}",
|
||||
e
|
||||
)));
|
||||
return Ready(Some(Err(e)));
|
||||
}
|
||||
Ready(None) => {
|
||||
self.current[i1] = CurVal::Finish;
|
||||
}
|
||||
Pending => {
|
||||
// TODO is this behaviour correct?
|
||||
return Pending;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
let mut lowest_ix = usize::MAX;
|
||||
let mut lowest_ts = u64::MAX;
|
||||
for i1 in 0..self.inps.len() {
|
||||
match &self.current[i1] {
|
||||
CurVal::Finish => {}
|
||||
CurVal::Val(val) => {
|
||||
let u = self.ixs[i1];
|
||||
if u >= val.tss.len() {
|
||||
self.ixs[i1] = 0;
|
||||
self.current[i1] = CurVal::None;
|
||||
continue 'outer;
|
||||
} else {
|
||||
let ts = val.tss[u];
|
||||
if ts < lowest_ts {
|
||||
lowest_ix = i1;
|
||||
lowest_ts = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
}
|
||||
if lowest_ix == usize::MAX {
|
||||
// TODO all inputs in finished state
|
||||
break Ready(None);
|
||||
} else {
|
||||
//trace!("decided on next lowest ts {} ix {}", lowest_ts, lowest_ix);
|
||||
self.batch.tss.push(lowest_ts);
|
||||
let rix = self.ixs[lowest_ix];
|
||||
match &mut self.current[lowest_ix] {
|
||||
CurVal::Val(ref mut k) => {
|
||||
let k = std::mem::replace(&mut k.values[rix], vec![]);
|
||||
self.batch.values.push(k);
|
||||
}
|
||||
_ => panic!(),
|
||||
}
|
||||
self.ixs[lowest_ix] += 1;
|
||||
}
|
||||
if self.batch.tss.len() >= 64 {
|
||||
let k = std::mem::replace(&mut self.batch, ValuesDim1::empty());
|
||||
let ret = Dim1F32StreamItem::Values(k);
|
||||
break Ready(Some(Ok(ret)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum CurVal {
|
||||
None,
|
||||
Finish,
|
||||
Err(Error),
|
||||
Val(ValuesDim1),
|
||||
}
|
||||
|
||||
pub struct MergedMinMaxAvgScalarStream<S>
|
||||
where
|
||||
S: Stream<Item = Result<MinMaxAvgScalarEventBatchStreamItem, Error>>,
|
||||
|
||||
Reference in New Issue
Block a user