quill_sql/execution/physical_plan/
project.rs1use std::sync::Arc;
2
3use crate::catalog::SchemaRef;
4use crate::expression::{Expr, ExprTrait};
5use crate::{
6 error::QuillSQLResult,
7 execution::{ExecutionContext, VolcanoExecutor},
8 storage::tuple::Tuple,
9};
10
11use super::PhysicalPlan;
12
13#[derive(derive_new::new, Debug)]
14pub struct PhysicalProject {
15 pub exprs: Vec<Expr>,
16 pub schema: SchemaRef,
17 pub input: Arc<PhysicalPlan>,
18}
19
20impl VolcanoExecutor for PhysicalProject {
21 fn init(&self, context: &mut ExecutionContext) -> QuillSQLResult<()> {
22 self.input.init(context)
23 }
24
25 fn next(&self, context: &mut ExecutionContext) -> QuillSQLResult<Option<Tuple>> {
26 if let Some(tuple) = self.input.next(context)? {
27 let mut new_values = Vec::new();
28 for expr in &self.exprs {
29 new_values.push(expr.evaluate(&tuple)?);
30 }
31 Ok(Some(Tuple::new(self.output_schema(), new_values)))
32 } else {
33 Ok(None)
34 }
35 }
36
37 fn output_schema(&self) -> SchemaRef {
38 self.schema.clone()
39 }
40}
41
42impl std::fmt::Display for PhysicalProject {
43 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
44 write!(f, "Project")
45 }
46}