risingwave_frontend/planner/
set_operation.rsuse risingwave_common::util::column_index_mapping::ColIndexMapping;
use crate::binder::{BoundSetExpr, BoundSetOperation};
use crate::error::Result;
use crate::optimizer::plan_node::{LogicalExcept, LogicalIntersect, LogicalProject, LogicalUnion};
use crate::planner::Planner;
use crate::PlanRef;
impl Planner {
pub(super) fn plan_set_operation(
&mut self,
op: BoundSetOperation,
all: bool,
corresponding_col_indices: Option<(ColIndexMapping, ColIndexMapping)>,
left: BoundSetExpr,
right: BoundSetExpr,
) -> Result<PlanRef> {
let left = self.plan_set_expr(left, vec![], &[])?;
let right = self.plan_set_expr(right, vec![], &[])?;
let (left, right) = if let Some((mapping_l, mapping_r)) = corresponding_col_indices {
(
LogicalProject::with_mapping(left, mapping_l).into(),
LogicalProject::with_mapping(right, mapping_r).into(),
)
} else {
(left, right)
};
match op {
BoundSetOperation::Union => Ok(LogicalUnion::create(all, vec![left, right])),
BoundSetOperation::Intersect => Ok(LogicalIntersect::create(all, vec![left, right])),
BoundSetOperation::Except => Ok(LogicalExcept::create(all, vec![left, right])),
}
}
}