Skip to main content

akar_processor/physical/write_ops/
physicalexplain.rs

1//! Auto-extracted from physical_operator.rs
2use crate::physical::types::{OperatorResult, PhysicalOperatorExec};
3use akar_common::types::PhysicalTypeID;
4use akar_common::vector::DataChunk;
5use std::sync::Arc;
6
7// ==================== PhysicalExplain ====================
8
9/// Physical EXPLAIN operator — serializes a logical plan tree to a human-readable
10/// string and returns it as a single-row result.
11///
12/// Corresponds to C++ `PlanPrinter::printPlanToOstream` and `mapExplain`.
13pub struct PhysicalExplain {
14    /// The inner logical operator tree to serialize.
15    pub inner_plan: String,
16}
17
18impl PhysicalOperatorExec for PhysicalExplain {
19    fn operator_type(&self) -> &str {
20        "explain"
21    }
22
23    fn execute(&self, _input: Vec<DataChunk>) -> OperatorResult {
24        let plan_str = self.inner_plan.clone();
25        // Build an Arrow string array directly so the plan is never truncated
26        // to the 255-byte inline string limit of the legacy value vector.
27        let array = Arc::new(arrow::array::StringArray::from(vec![plan_str]));
28        let arrow = akar_common::arrow_vector::ArrowVector::new(array, PhysicalTypeID::String);
29        let chunk = DataChunk {
30            fields: vec![arrow.array],
31            field_types: vec![PhysicalTypeID::String],
32            size: 1,
33            field_names: vec![],
34            sel_vector: None,
35        };
36        Ok(vec![chunk])
37    }
38}