Skip to main content

linkrs_query/executor/streaming/operators/spec/
exchange.rs

1//! Immutable configuration for exchange (gather / merge / repartition) operators.
2
3use crate::executor::streaming::executor::SortDirection;
4use crate::executor::streaming::slot::SlotLayout;
5use linkrs_core::types::expr::Expression;
6
7/// Immutable config for exchange (gather / merge / repartition) operators.
8///
9/// Workers in the shared engine-level scheduler execute partition tasks
10/// dynamically via a morsel-style shared atomic counter.
11#[derive(Debug, Clone)]
12pub enum ExchangeSpec {
13    /// Concatenate N partition outputs in partition order.
14    Concatenate { partition_count: usize },
15    /// N-way merge-sort of pre-sorted partition inputs.
16    MergeSort {
17        sort_expressions: Vec<Expression>,
18        sort_directions: Vec<SortDirection>,
19        limit: Option<usize>,
20    },
21    /// Hash-based repartition: partition rows by hash of keys into N buckets.
22    ///
23    /// Each child produces output for one partition; the operator collects,
24    /// rehashes, and routes rows to the correct output bucket.  Used by hash
25    /// join and hash aggregate to align partition boundaries.
26    RepartitionHash {
27        /// Number of output buckets / partitions.
28        num_partitions: usize,
29        /// Expressions whose hash determines the output partition.
30        hash_expressions: Vec<Expression>,
31        /// Column names / slot layout of the input rows.
32        input_layout: Option<SlotLayout>,
33        /// Column names / slot layout of the output rows.
34        output_layout: Option<SlotLayout>,
35    },
36    /// Broadcast: replicate every input row to all consumers.
37    ///
38    /// Used to distribute a small build-side to all probe-side partitions.
39    /// The input chunk is shallow-copied (Arc-like) or deep-cloned for each
40    /// consumer depending on size.
41    Broadcast {
42        /// Number of output channels.
43        num_consumers: usize,
44    },
45    /// Barrier: wait for all input fragments to complete before producing
46    /// any output row.
47    ///
48    /// Used to sequence blocking stages (e.g. wait for build side before
49    /// probe).  No data rearrangement; the first input's layout passes
50    /// through.
51    Barrier,
52    /// Materialize: force an upstream fragment to fully materialise before
53    /// the consumer fragment starts.
54    ///
55    /// Used for explicit spooling / break-fanout patterns and to isolate
56    /// lifecycle across fragment boundaries.  Behaves like Concatenate but
57    /// signals a pipeline break to the scheduler and validator.
58    Materialize {
59        /// Expected number of child inputs (all must be consumed).
60        child_count: usize,
61    },
62}