jayzhan211 commented on code in PR #26269:
URL: https://github.com/apache/datafusion/pull/26269#discussion_r4366534277
##########
datafusion/expr/src/logical_plan/materialized_cte.rs:
##########
@@ -62,91 +65,198 @@ impl fmt::Display for MaterializedCteId {
}
}
+/// A node of a materialized CTE, in [`LogicalPlan::MaterializedCte`].
+#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Hash)]
+pub enum MaterializedCtePlan {
+ /// Computes the body of the CTE once and evaluates the continuation
+ Cte(MaterializedCte),
+ /// Reads the buffered output of the CTE. This is a leaf.
+ Scan(MaterializedCteScan),
+}
+
/// Computes `cte` once and evaluates `continuation`, in which every
/// [`MaterializedCteScan`] with the same `id` reads the buffered output of
/// `cte`. The output of this node is the output of `continuation`.
+///
+/// The node has two inputs with different roles, in this order:
+///
+/// 1. `cte`: the body of the CTE. It is shared by all the scans, so a rule
+/// must not change its schema, and must not push into it a filter, limit
+/// or projection that belongs to one scan only.
+/// 2. `continuation`: the query that declared the CTE.
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct MaterializedCte {
+ /// Binds the scans in `continuation` to this node
pub id: MaterializedCteId,
+ /// Name of the CTE, used for display and error messages only
pub name: String,
- pub cte: LogicalPlan,
- pub continuation: LogicalPlan,
+ /// The body of the CTE
+ pub cte: Arc<LogicalPlan>,
Review Comment:
nit: the field is `cte` but the accessor is `body()`, so call sites end up
reading `cte.cte` (e.g. in `decorrelate.rs` and `optimize_projections`). Since
#25580 hasn't shipped in a release yet, renaming the field to `body` now would
be free:
```diff
- pub cte: Arc<LogicalPlan>,
+ pub body: Arc<LogicalPlan>,
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]