use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::time::{Duration, Instant};
use timely::dataflow::operators::capture::event::link::EventLink;
use timely::dataflow::{ProbeHandle, Scope, Stream};
use timely::logging::TimelyEvent;
use timely::progress::Timestamp;
use differential_dataflow::lattice::Lattice;
use differential_dataflow::logging::DifferentialEvent;
use crate::server::scheduler::Scheduler;
use crate::AttributeConfig;
use crate::{Aid, Value};
#[cfg(feature = "csv-source")]
pub mod csv_file;
pub mod differential_logging;
pub mod timely_logging;
#[cfg(feature = "csv-source")]
pub use self::csv_file::CsvFile;
pub struct SourcingContext<T: Timestamp> {
pub t0: Instant,
pub domain_probe: ProbeHandle<T>,
pub scheduler: Weak<RefCell<Scheduler>>,
pub timely_events: Rc<EventLink<Duration, (Duration, usize, TimelyEvent)>>,
pub differential_events: Rc<EventLink<Duration, (Duration, usize, DifferentialEvent)>>,
}
pub trait Sourceable<S>
where
S: Scope,
S::Timestamp: Timestamp + Lattice,
{
fn source(
&self,
scope: &mut S,
context: SourcingContext<S::Timestamp>,
) -> Vec<(
Aid,
AttributeConfig,
Stream<S, ((Value, Value), S::Timestamp, isize)>,
)>;
}
#[derive(Hash, PartialEq, Eq, PartialOrd, Ord, Clone, Debug, Serialize, Deserialize)]
pub enum Source {
TimelyLogging(timely_logging::TimelyLogging),
DifferentialLogging(differential_logging::DifferentialLogging),
#[cfg(feature = "csv-source")]
CsvFile(CsvFile),
}
#[cfg(feature = "real-time")]
impl<S: Scope<Timestamp = Duration>> Sourceable<S> for Source {
fn source(
&self,
scope: &mut S,
context: SourcingContext<S::Timestamp>,
) -> Vec<(
Aid,
AttributeConfig,
Stream<S, ((Value, Value), Duration, isize)>,
)> {
match *self {
Source::TimelyLogging(ref source) => source.source(scope, context),
Source::DifferentialLogging(ref source) => source.source(scope, context),
#[cfg(feature = "csv-source")]
Source::CsvFile(ref source) => source.source(scope, context),
_ => unimplemented!(),
}
}
}
#[cfg(not(feature = "real-time"))]
impl<S: Scope> Sourceable<S> for Source
where
S::Timestamp: Timestamp + Lattice,
{
fn source(
&self,
_scope: &mut S,
_context: SourcingContext<S::Timestamp>,
) -> Vec<(
Aid,
AttributeConfig,
Stream<S, ((Value, Value), S::Timestamp, isize)>,
)> {
unimplemented!();
}
}