#![allow(dead_code, missing_docs)]
use differential_dataflow::operators::arrange::Arranged;
use differential_dataflow::operators::arrange::TraceAgent;
use differential_dataflow::trace::implementations::chunker::ColumnationChunker;
use differential_dataflow::trace::implementations::merge_batcher::MergeBatcher;
use differential_dataflow::trace::implementations::merge_batcher_col::ColumnationMerger;
use differential_dataflow::trace::implementations::ord_neu::{FlatValSpine, OrdValBatch};
use differential_dataflow::trace::wrappers::enter::TraceEnter;
use differential_dataflow::trace::wrappers::frontier::TraceFrontier;
use mz_ore::flatcontainer::MzRegionPreference;
use mz_repr::Diff;
use mz_storage_types::errors::DataflowError;
use timely::container::flatcontainer::impls::tuple::{TupleABCRegion, TupleABRegion};
use timely::dataflow::ScopeParent;
pub use crate::row_spine::{RowRowSpine, RowSpine, RowValSpine};
use crate::typedefs::spines::MzFlatLayout;
pub use crate::typedefs::spines::{ColKeySpine, ColValSpine};
pub(crate) mod spines {
use std::rc::Rc;
use differential_dataflow::difference::Semigroup;
use differential_dataflow::lattice::Lattice;
use differential_dataflow::trace::implementations::ord_neu::{
OrdKeyBatch, OrdKeyBuilder, OrdValBatch, OrdValBuilder,
};
use differential_dataflow::trace::implementations::spine_fueled::Spine;
use differential_dataflow::trace::implementations::{Layout, Update};
use differential_dataflow::trace::rc_blanket_impls::RcBuilder;
use mz_timely_util::containers::stack::StackWrapper;
use timely::container::columnation::{Columnation, TimelyStack};
use timely::container::flatcontainer::{FlatStack, Push, Region};
use timely::progress::Timestamp;
use crate::row_spine::OffsetOptimized;
use crate::typedefs::{KeyBatcher, KeyValBatcher};
pub type ColValSpine<K, V, T, R> = Spine<
Rc<OrdValBatch<MzStack<((K, V), T, R)>>>,
KeyValBatcher<K, V, T, R>,
RcBuilder<OrdValBuilder<MzStack<((K, V), T, R)>, TimelyStack<((K, V), T, R)>>>,
>;
pub type ColKeySpine<K, T, R> = Spine<
Rc<OrdKeyBatch<MzStack<((K, ()), T, R)>>>,
KeyBatcher<K, T, R>,
RcBuilder<OrdKeyBuilder<MzStack<((K, ()), T, R)>, TimelyStack<((K, ()), T, R)>>>,
>;
pub struct MzStack<U: Update> {
phantom: std::marker::PhantomData<U>,
}
impl<U: Update> Layout for MzStack<U>
where
U::Key: Columnation + 'static,
U::Val: Columnation + 'static,
U::Time: Columnation,
U::Diff: Columnation,
{
type Target = U;
type KeyContainer = StackWrapper<U::Key>;
type ValContainer = StackWrapper<U::Val>;
type TimeContainer = StackWrapper<U::Time>;
type DiffContainer = StackWrapper<U::Diff>;
type OffsetContainer = OffsetOptimized;
}
pub struct MzFlatLayout<K, V, T, R> {
phantom: std::marker::PhantomData<(K, V, T, R)>,
}
impl<K, V, T, R> Update for MzFlatLayout<K, V, T, R>
where
K: Region,
V: Region,
T: Region,
R: Region,
K::Owned: Ord + Clone + 'static,
V::Owned: Ord + Clone + 'static,
T::Owned: Ord + Clone + Lattice + Timestamp + 'static,
R::Owned: Ord + Semigroup + 'static,
{
type Key = K::Owned;
type Val = V::Owned;
type Time = T::Owned;
type Diff = R::Owned;
}
impl<K, V, T, R> Layout for MzFlatLayout<K, V, T, R>
where
K: Region
+ Push<<K as Region>::Owned>
+ for<'a> Push<<K as Region>::ReadItem<'a>>
+ 'static,
V: Region
+ Push<<V as Region>::Owned>
+ for<'a> Push<<V as Region>::ReadItem<'a>>
+ 'static,
T: Region
+ Push<<T as Region>::Owned>
+ for<'a> Push<<T as Region>::ReadItem<'a>>
+ 'static,
R: Region
+ Push<<R as Region>::Owned>
+ for<'a> Push<<R as Region>::ReadItem<'a>>
+ 'static,
K::Owned: Ord + Clone + 'static,
V::Owned: Ord + Clone + 'static,
T::Owned: Ord + Clone + Lattice + Timestamp + 'static,
R::Owned: Ord + Semigroup + 'static,
for<'a> K::ReadItem<'a>: Copy + Ord,
for<'a> V::ReadItem<'a>: Copy + Ord,
for<'a> T::ReadItem<'a>: Copy + Ord,
for<'a> R::ReadItem<'a>: Copy + Ord,
{
type Target = Self;
type KeyContainer = FlatStack<K>;
type ValContainer = FlatStack<V>;
type TimeContainer = FlatStack<T>;
type DiffContainer = FlatStack<R>;
type OffsetContainer = OffsetOptimized;
}
}
pub type KeyValSpine<K, V, T, R> = ColValSpine<K, V, T, R>;
pub type KeyValAgent<K, V, T, R> = TraceAgent<KeyValSpine<K, V, T, R>>;
pub type KeyValEnter<K, V, T, R, TEnter> =
TraceEnter<TraceFrontier<KeyValAgent<K, V, T, R>>, TEnter>;
pub type KeySpine<K, T, R> = ColKeySpine<K, T, R>;
pub type KeyAgent<K, T, R> = TraceAgent<KeySpine<K, T, R>>;
pub type KeyEnter<K, T, R, TEnter> = TraceEnter<TraceFrontier<KeyAgent<K, T, R>>, TEnter>;
pub type RowValAgent<V, T, R> = TraceAgent<RowValSpine<V, T, R>>;
pub type RowValArrangement<S, V> = Arranged<S, RowValAgent<V, <S as ScopeParent>::Timestamp, Diff>>;
pub type RowValEnter<V, T, R, TEnter> = TraceEnter<TraceFrontier<RowValAgent<V, T, R>>, TEnter>;
pub type RowRowAgent<T, R> = TraceAgent<RowRowSpine<T, R>>;
pub type RowRowArrangement<S> = Arranged<S, RowRowAgent<<S as ScopeParent>::Timestamp, Diff>>;
pub type RowRowEnter<T, R, TEnter> = TraceEnter<TraceFrontier<RowRowAgent<T, R>>, TEnter>;
pub type RowAgent<T, R> = TraceAgent<RowSpine<T, R>>;
pub type RowArrangement<S> = Arranged<S, RowAgent<<S as ScopeParent>::Timestamp, Diff>>;
pub type RowEnter<T, R, TEnter> = TraceEnter<TraceFrontier<RowAgent<T, R>>, TEnter>;
pub type ErrSpine<T, R> = ColKeySpine<DataflowError, T, R>;
pub type ErrAgent<T, R> = TraceAgent<ErrSpine<T, R>>;
pub type ErrEnter<T, TEnter> = TraceEnter<TraceFrontier<ErrAgent<T, Diff>>, TEnter>;
pub type KeyErrSpine<K, T, R> = ColValSpine<K, DataflowError, T, R>;
pub type RowErrSpine<T, R> = RowValSpine<DataflowError, T, R>;
pub type KeyBatcher<K, T, D> = KeyValBatcher<K, (), T, D>;
pub type KeyValBatcher<K, V, T, D> = MergeBatcher<
Vec<((K, V), T, D)>,
ColumnationChunker<((K, V), T, D)>,
ColumnationMerger<((K, V), T, D)>,
T,
>;
pub type FlatKeyValBatch<K, V, T, R> = OrdValBatch<MzFlatLayout<K, V, T, R>>;
pub type FlatKeyValSpine<K, V, T, R, C> =
FlatValSpine<MzFlatLayout<K, V, T, R>, TupleABCRegion<TupleABRegion<K, V>, T, R>, C>;
pub type FlatKeyValSpineDefault<K, V, T, R, C> = FlatKeyValSpine<
<K as MzRegionPreference>::Region,
<V as MzRegionPreference>::Region,
<T as MzRegionPreference>::Region,
<R as MzRegionPreference>::Region,
C,
>;
pub type FlatKeyValAgent<K, V, T, R, C> = TraceAgent<FlatKeyValSpine<K, V, T, R, C>>;
pub type FlatKeyValEnter<K, V, T, R, C, TEnter> =
TraceEnter<TraceFrontier<FlatKeyValAgent<K, V, T, R, C>>, TEnter>;