Skip to main content

nodedb_lite/query/query_ops/joins/
spec.rs

1// SPDX-License-Identifier: Apache-2.0
2//! Parameter structs shared by the hash, broadcast, and inline-hash join executors.
3
4use nodedb_physical::physical_plan::query::JoinProjection;
5
6/// A join input read from a named collection.
7pub struct CollectionSide<'a> {
8    pub collection: &'a str,
9    pub alias: Option<&'a str>,
10}
11
12/// Join behavior shared by every join strategy.
13pub struct JoinSpec<'a> {
14    /// `(left_key, right_key)` equality pairs.
15    pub on: &'a [(String, String)],
16    pub join_type: &'a str,
17    /// Row cap on the join output. `0` means unlimited.
18    pub limit: usize,
19    pub projection: &'a [JoinProjection],
20    /// Msgpack-encoded post-join filters. Empty means no filter.
21    pub post_filters: &'a [u8],
22}
23
24impl JoinSpec<'_> {
25    /// Left and right key columns split out of `on`.
26    pub(super) fn split_keys(&self) -> (Vec<String>, Vec<String>) {
27        let left = self.on.iter().map(|(l, _)| l.clone()).collect();
28        let right = self.on.iter().map(|(_, r)| r.clone()).collect();
29        (left, right)
30    }
31
32    /// `limit` with `0` mapped to `usize::MAX`.
33    pub(super) fn effective_limit(&self) -> usize {
34        if self.limit == 0 {
35            usize::MAX
36        } else {
37            self.limit
38        }
39    }
40}