Skip to main content

uqa_execution/relational/
set_operation.rs

1//
2// Unified Query Algebra
3//
4// Copyright (c) 2023-2026 Cognica, Inc.
5//
6
7//! Byte-bounded SQL set operations.
8
9use super::{Batch, ExecResult, PhysicalOperator, SetOpKind};
10
11/// Byte-bounded compatibility wrapper for SQL set operations.
12///
13/// All forms other than `UNION ALL` externally sort and merge their inputs;
14/// `UNION ALL` streams both children. Construction is fallible because input
15/// widths must agree.
16pub struct SetOperation<'a> {
17    inner: crate::set_operation::ExternalSetOperation<'a>,
18}
19
20impl<'a> SetOperation<'a> {
21    pub fn new(
22        left: Box<dyn PhysicalOperator + 'a>,
23        right: Box<dyn PhysicalOperator + 'a>,
24        kind: SetOpKind,
25        all: bool,
26    ) -> ExecResult<Self> {
27        Self::new_with_work_mem(left, right, kind, all, 64 * 1024 * 1024)
28    }
29
30    pub fn new_with_work_mem(
31        left: Box<dyn PhysicalOperator + 'a>,
32        right: Box<dyn PhysicalOperator + 'a>,
33        kind: SetOpKind,
34        all: bool,
35        work_mem_bytes: usize,
36    ) -> ExecResult<Self> {
37        Ok(Self {
38            inner: crate::set_operation::ExternalSetOperation::new(
39                left,
40                right,
41                kind,
42                all,
43                work_mem_bytes,
44            )?,
45        })
46    }
47}
48
49impl PhysicalOperator for SetOperation<'_> {
50    fn row_schema(&self) -> &super::RowSchema {
51        self.inner.row_schema()
52    }
53
54    fn open(&mut self) -> ExecResult<()> {
55        self.inner.open()
56    }
57
58    fn next(&mut self) -> ExecResult<Option<Batch>> {
59        self.inner.next()
60    }
61
62    fn close(&mut self) -> ExecResult<()> {
63        self.inner.close()
64    }
65}
66
67// -------------------------------------------------------------------------
68// Hash aggregate
69// -------------------------------------------------------------------------