use glaredb_error::Result;
use super::binder::bind_context::BindContext;
use super::binder::table_list::TableRef;
use super::operator::{LogicalNode, Node};
use crate::explain::explainable::{EntryBuilder, ExplainConfig, ExplainEntry, Explainable};
use crate::expr::Expression;
#[derive(Debug, Clone, PartialEq)]
pub struct LogicalProject {
pub projections: Vec<Expression>,
pub projection_table: TableRef,
}
impl Explainable for LogicalProject {
fn explain_entry(&self, conf: ExplainConfig) -> ExplainEntry {
EntryBuilder::new("Project", conf)
.with_contextual_values("projections", &self.projections)
.with_value_if_verbose("table_ref", self.projection_table)
.build()
}
}
impl LogicalNode for Node<LogicalProject> {
fn name(&self) -> &'static str {
"Project"
}
fn get_output_table_refs(&self, _bind_context: &BindContext) -> Vec<TableRef> {
vec![self.node.projection_table]
}
fn for_each_expr<'a, F>(&'a self, mut func: F) -> Result<()>
where
F: FnMut(&'a Expression) -> Result<()>,
{
for expr in &self.node.projections {
func(expr)?;
}
Ok(())
}
fn for_each_expr_mut<'a, F>(&'a mut self, mut func: F) -> Result<()>
where
F: FnMut(&'a mut Expression) -> Result<()>,
{
for expr in &mut self.node.projections {
func(expr)?;
}
Ok(())
}
}