Skip to content

Commit 175ed67

Browse files
committed
compute: make mz_join_core generic over a container builder
`mz_join_core` took its output container as a type parameter and wrapped it in a `CapacityContainerBuilder` internally, which fixed how the output is assembled. Taking the container builder instead lets a caller choose the assembly, for example a `ColumnBuilder` that produces the columnar edge directly rather than a `Vec` a later operator has to re-encode. `Work::process` follows the same change, and `LinearJoinSpec::render` names `CapacityContainerBuilder<Vec<_>>` explicitly at the call sites, so this commit is behavior-preserving on its own.
1 parent 1f1da8a commit 175ed67

2 files changed

Lines changed: 33 additions & 14 deletions

File tree

src/compute/src/render/join/linear_join.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use mz_timely_util::columnar::builder::ColumnBuilder;
3636
use mz_timely_util::columnar::consolidate::ConsolidatingColumnBuilder;
3737
use mz_timely_util::columnar::{Col2ValBatcher, Col2ValPagedBatcher, columnar_exchange};
3838
use mz_timely_util::operator::{CollectionExt, StreamExt};
39+
use timely::container::CapacityContainerBuilder;
3940
use timely::dataflow::channels::pact::{ExchangeCore, Pipeline};
4041
use timely::dataflow::operators::OkErr;
4142
use timely::dataflow::{Scope, Stream};
@@ -118,6 +119,10 @@ impl LinearJoinSpec {
118119
{
119120
use LinearJoinImpl::*;
120121

122+
// `mz_join_core` builds its output through a container builder. The
123+
// `Vec` accumulator this method returns needs the capacity builder.
124+
type VecCB<D, T> = CapacityContainerBuilder<Vec<(D, T, Diff)>>;
125+
121126
match (
122127
self.implementation,
123128
self.yielding.after_work,
@@ -127,19 +132,31 @@ impl LinearJoinSpec {
127132
(Materialize, Some(work_limit), Some(time_limit)) => {
128133
let yield_fn =
129134
move |start: Instant, work| work >= work_limit || start.elapsed() >= time_limit;
130-
mz_join_core(arranged1, arranged2, result, yield_fn).as_collection()
135+
mz_join_core::<_, _, _, _, _, _, VecCB<I::Item, T>>(
136+
arranged1, arranged2, result, yield_fn,
137+
)
138+
.as_collection()
131139
}
132140
(Materialize, Some(work_limit), None) => {
133141
let yield_fn = move |_start, work| work >= work_limit;
134-
mz_join_core(arranged1, arranged2, result, yield_fn).as_collection()
142+
mz_join_core::<_, _, _, _, _, _, VecCB<I::Item, T>>(
143+
arranged1, arranged2, result, yield_fn,
144+
)
145+
.as_collection()
135146
}
136147
(Materialize, None, Some(time_limit)) => {
137148
let yield_fn = move |start: Instant, _work| start.elapsed() >= time_limit;
138-
mz_join_core(arranged1, arranged2, result, yield_fn).as_collection()
149+
mz_join_core::<_, _, _, _, _, _, VecCB<I::Item, T>>(
150+
arranged1, arranged2, result, yield_fn,
151+
)
152+
.as_collection()
139153
}
140154
(Materialize, None, None) => {
141155
let yield_fn = |_start, _work| false;
142-
mz_join_core(arranged1, arranged2, result, yield_fn).as_collection()
156+
mz_join_core::<_, _, _, _, _, _, VecCB<I::Item, T>>(
157+
arranged1, arranged2, result, yield_fn,
158+
)
159+
.as_collection()
143160
}
144161
}
145162
}

src/compute/src/render/join/mz_join_core.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,25 @@ use differential_dataflow::trace::cursor::{BatchCursor, BatchKey, BatchVal, Curs
4141
use differential_dataflow::trace::{BatchReader, Cursor, Navigable, TraceReader};
4242
use mz_ore::future::yield_now;
4343
use mz_repr::Diff;
44-
use timely::container::{CapacityContainerBuilder, PushInto, SizableContainer};
44+
use timely::container::PushInto;
4545
use timely::dataflow::Stream;
4646
use timely::dataflow::channels::pact::Pipeline;
4747
use timely::dataflow::operators::generic::OutputBuilderSession;
4848
use timely::dataflow::operators::{Capability, Operator};
49-
use timely::{Container, PartialOrder};
49+
use timely::{ContainerBuilder, PartialOrder};
5050
use tracing::trace;
5151

5252
/// Joins two arranged collections with the same key type.
5353
///
5454
/// Each matching pair of records `(key, val1)` and `(key, val2)` are subjected to the `result` function,
5555
/// which produces something implementing `IntoIterator`, where the output collection will have an entry for
5656
/// every value returned by the iterator.
57-
pub(super) fn mz_join_core<'scope, T, Tr1, Tr2, L, I, YFn, C>(
57+
pub(super) fn mz_join_core<'scope, T, Tr1, Tr2, L, I, YFn, CB>(
5858
arranged1: Arranged<'scope, Tr1>,
5959
arranged2: Arranged<'scope, Tr2>,
6060
result: L,
6161
yield_fn: YFn,
62-
) -> Stream<'scope, T, C>
62+
) -> Stream<'scope, T, CB::Container>
6363
where
6464
T: timely::progress::Timestamp + Lattice,
6565
Tr1: TraceReader<Batch: Navigable, Time = T> + Clone + 'static,
@@ -69,13 +69,13 @@ where
6969
L: FnMut(BatchKey<'_, Tr1>, BatchVal<'_, Tr1>, BatchVal<'_, Tr2>) -> I + 'static,
7070
I: IntoIterator<Item: Data> + 'static,
7171
YFn: Fn(Instant, usize) -> bool + 'static,
72-
C: Container + SizableContainer + PushInto<(I::Item, T, Diff)> + Data,
72+
CB: ContainerBuilder + PushInto<(I::Item, T, Diff)> + 'static,
7373
{
7474
let scope = arranged1.stream.scope();
7575
let mut trace1 = arranged1.trace.clone();
7676
let mut trace2 = arranged2.trace.clone();
7777

78-
arranged1.stream.binary_frontier(
78+
arranged1.stream.binary_frontier::<_, CB, _, _, _, _>(
7979
arranged2.stream,
8080
Pipeline,
8181
Pipeline,
@@ -572,12 +572,12 @@ where
572572
}
573573

574574
/// Process pending work until none is remaining or `yield_fn` requests a yield.
575-
fn process<C, YFn>(
575+
fn process<CB, YFn>(
576576
&mut self,
577-
output: &mut OutputBuilderSession<'_, C1::Time, CapacityContainerBuilder<C>>,
577+
output: &mut OutputBuilderSession<'_, C1::Time, CB>,
578578
yield_fn: YFn,
579579
) where
580-
C: Container + SizableContainer + PushInto<(D, C1::Time, Diff)> + Data,
580+
CB: ContainerBuilder + PushInto<(D, C1::Time, Diff)>,
581581
YFn: Fn(Instant, usize) -> bool,
582582
{
583583
let start_time = Instant::now();
@@ -605,7 +605,9 @@ where
605605
let recovered = old_len - output_buf.len();
606606
self.produced.update(|x| x - recovered);
607607

608-
output.session(&cap).give_iterator(output_buf.drain(..));
608+
output
609+
.session_with_builder(&cap)
610+
.give_iterator(output_buf.drain(..));
609611

610612
if done {
611613
// We have finished processing a chunk of work. Use this opportunity to truncate

0 commit comments

Comments
 (0)