Skip to main content

vortex_layout/plan/
vtable.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4use std::borrow::Cow;
5use std::fmt;
6use std::fmt::Debug;
7
8use vortex_array::DeserializeMetadata;
9use vortex_array::SerializeMetadata;
10use vortex_error::VortexResult;
11use vortex_session::registry::Id;
12
13use crate::plan::PlanChildren;
14use crate::plan::typed::Plan;
15
16/// A unique identifier for a plan operator.
17pub type PlanId = Id;
18
19/// Operator-specific behavior for a typed [`Plan`].
20///
21/// Common fields — dtype, row count, and children — are stored outside the erased operator data.
22/// Implementations own only their operator-specific data, its metadata codec, and a callback for
23/// refreshing cached data after generic child replacement.
24///
25/// Operators describe physical work over a row domain. Their identity and operator-specific data
26/// do not depend on the source layout kind. The common lazy-child storage may nevertheless own a
27/// hidden source-layout reference used for on-demand lowering.
28pub trait PlanVTable: 'static + Clone + Sized + Send + Sync + Debug {
29    /// Operator-specific data, excluding children.
30    ///
31    /// Children belong in [`PlanParts::children`](crate::plan::PlanParts::children) so that
32    /// traversal and rewriting can discover them generically.
33    type PlanData: 'static + Send + Sync + Clone + Debug;
34
35    /// Serialized form of [`PlanData`](Self::PlanData).
36    type Metadata: SerializeMetadata + DeserializeMetadata + Debug;
37
38    /// Returns the globally unique operator ID.
39    fn id(&self) -> PlanId;
40
41    /// Writes operator-specific fields after the plan's standard display summary.
42    fn fmt(plan: &Plan<Self>, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
43        let _ = (plan, formatter);
44        Ok(())
45    }
46
47    /// Returns the serializable metadata for this operator.
48    ///
49    /// Returns `None` when the operator holds state that cannot be serialized.
50    fn metadata(plan: &Plan<Self>) -> Option<Self::Metadata>;
51
52    /// Refreshes cloned operator data after the common child container is replaced.
53    ///
54    /// The plan layer clones [`PlanData`](Self::PlanData), replaces the children externally, and
55    /// invokes this callback. Implementations validate the new children and update any derived
56    /// values in `data`; they do not rebuild the plan itself.
57    fn with_children(
58        plan: &Plan<Self>,
59        children: &PlanChildren,
60        data: &mut Self::PlanData,
61    ) -> VortexResult<()> {
62        let _ = (plan, children, data);
63        Ok(())
64    }
65
66    /// Returns the display name of the child at `index`.
67    fn child_name(plan: &Plan<Self>, index: usize) -> Cow<'_, str> {
68        let _ = plan;
69        Cow::Owned(format!("child[{index}]"))
70    }
71}