mz_compute/
typedefs.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Convience typedefs for differential types.
11
12#![allow(dead_code, missing_docs)]
13
14use differential_dataflow::operators::arrange::Arranged;
15use differential_dataflow::operators::arrange::TraceAgent;
16use differential_dataflow::trace::implementations::chunker::ColumnationChunker;
17use differential_dataflow::trace::implementations::merge_batcher::{ColMerger, MergeBatcher};
18use differential_dataflow::trace::wrappers::enter::TraceEnter;
19use differential_dataflow::trace::wrappers::frontier::TraceFrontier;
20use mz_repr::Diff;
21use mz_storage_types::errors::DataflowError;
22use timely::dataflow::ScopeParent;
23
24use crate::row_spine::RowValBuilder;
25use crate::typedefs::spines::{ColKeyBatcher, ColKeyBuilder, ColValBatcher, ColValBuilder};
26
27pub use crate::row_spine::{RowRowSpine, RowSpine, RowValBatcher, RowValSpine};
28pub use crate::typedefs::spines::{ColKeySpine, ColValSpine};
29
30pub(crate) mod spines {
31    use std::rc::Rc;
32
33    use differential_dataflow::containers::{Columnation, TimelyStack};
34    use differential_dataflow::trace::implementations::ord_neu::{
35        OrdKeyBatch, OrdKeyBuilder, OrdValBatch, OrdValBuilder,
36    };
37    use differential_dataflow::trace::implementations::spine_fueled::Spine;
38    use differential_dataflow::trace::implementations::{Layout, Update};
39    use differential_dataflow::trace::rc_blanket_impls::RcBuilder;
40
41    use crate::row_spine::OffsetOptimized;
42    use crate::typedefs::{KeyBatcher, KeyValBatcher};
43
44    /// A spine for generic keys and values.
45    pub type ColValSpine<K, V, T, R> = Spine<Rc<OrdValBatch<MzStack<((K, V), T, R)>>>>;
46    pub type ColValBatcher<K, V, T, R> = KeyValBatcher<K, V, T, R>;
47    pub type ColValBuilder<K, V, T, R> =
48        RcBuilder<OrdValBuilder<MzStack<((K, V), T, R)>, TimelyStack<((K, V), T, R)>>>;
49
50    /// A spine for generic keys
51    pub type ColKeySpine<K, T, R> = Spine<Rc<OrdKeyBatch<MzStack<((K, ()), T, R)>>>>;
52    pub type ColKeyBatcher<K, T, R> = KeyBatcher<K, T, R>;
53    pub type ColKeyBuilder<K, T, R> =
54        RcBuilder<OrdKeyBuilder<MzStack<((K, ()), T, R)>, TimelyStack<((K, ()), T, R)>>>;
55
56    /// A layout based on chunked timely stacks
57    pub struct MzStack<U: Update> {
58        phantom: std::marker::PhantomData<U>,
59    }
60
61    impl<U: Update> Layout for MzStack<U>
62    where
63        U::Key: Columnation + 'static,
64        U::Val: Columnation + 'static,
65        U::Time: Columnation,
66        U::Diff: Columnation,
67    {
68        type Target = U;
69        type KeyContainer = TimelyStack<U::Key>;
70        type ValContainer = TimelyStack<U::Val>;
71        type TimeContainer = TimelyStack<U::Time>;
72        type DiffContainer = TimelyStack<U::Diff>;
73        type OffsetContainer = OffsetOptimized;
74    }
75}
76
77// Spines are data structures that collect and maintain updates.
78// Agents are wrappers around spines that allow shared read access.
79
80// Fully generic spines and agents.
81pub type KeyValSpine<K, V, T, R> = ColValSpine<K, V, T, R>;
82pub type KeyValAgent<K, V, T, R> = TraceAgent<KeyValSpine<K, V, T, R>>;
83pub type KeyValEnter<K, V, T, R, TEnter> =
84    TraceEnter<TraceFrontier<KeyValAgent<K, V, T, R>>, TEnter>;
85
86// Fully generic key-only spines and agents
87pub type KeySpine<K, T, R> = ColKeySpine<K, T, R>;
88pub type KeyAgent<K, T, R> = TraceAgent<KeySpine<K, T, R>>;
89pub type KeyEnter<K, T, R, TEnter> = TraceEnter<TraceFrontier<KeyAgent<K, T, R>>, TEnter>;
90
91// Row specialized spines and agents.
92pub type RowValAgent<V, T, R> = TraceAgent<RowValSpine<V, T, R>>;
93pub type RowValArrangement<S, V> = Arranged<S, RowValAgent<V, <S as ScopeParent>::Timestamp, Diff>>;
94pub type RowValEnter<V, T, R, TEnter> = TraceEnter<TraceFrontier<RowValAgent<V, T, R>>, TEnter>;
95// Row specialized spines and agents.
96pub type RowRowAgent<T, R> = TraceAgent<RowRowSpine<T, R>>;
97pub type RowRowArrangement<S> = Arranged<S, RowRowAgent<<S as ScopeParent>::Timestamp, Diff>>;
98pub type RowRowEnter<T, R, TEnter> = TraceEnter<TraceFrontier<RowRowAgent<T, R>>, TEnter>;
99// Row specialized spines and agents.
100pub type RowAgent<T, R> = TraceAgent<RowSpine<T, R>>;
101pub type RowArrangement<S> = Arranged<S, RowAgent<<S as ScopeParent>::Timestamp, Diff>>;
102pub type RowEnter<T, R, TEnter> = TraceEnter<TraceFrontier<RowAgent<T, R>>, TEnter>;
103
104// Error specialized spines and agents.
105pub type ErrSpine<T, R> = ColKeySpine<DataflowError, T, R>;
106pub type ErrBatcher<T, R> = ColKeyBatcher<DataflowError, T, R>;
107pub type ErrBuilder<T, R> = ColKeyBuilder<DataflowError, T, R>;
108
109pub type ErrAgent<T, R> = TraceAgent<ErrSpine<T, R>>;
110pub type ErrEnter<T, TEnter> = TraceEnter<TraceFrontier<ErrAgent<T, Diff>>, TEnter>;
111
112pub type KeyErrSpine<K, T, R> = ColValSpine<K, DataflowError, T, R>;
113pub type KeyErrBatcher<K, T, R> = ColValBatcher<K, DataflowError, T, R>;
114pub type KeyErrBuilder<K, T, R> = ColValBuilder<K, DataflowError, T, R>;
115
116pub type RowErrSpine<T, R> = RowValSpine<DataflowError, T, R>;
117pub type RowErrBatcher<T, R> = RowValBatcher<DataflowError, T, R>;
118pub type RowErrBuilder<T, R> = RowValBuilder<DataflowError, T, R>;
119
120// Batchers for consolidation
121pub type KeyBatcher<K, T, D> = KeyValBatcher<K, (), T, D>;
122pub type KeyValBatcher<K, V, T, D> =
123    MergeBatcher<Vec<((K, V), T, D)>, ColumnationChunker<((K, V), T, D)>, ColMerger<(K, V), T, D>>;