Repository navigation
Conversation
5b625f0 to
bdf3a4d
Compare
A rule that builds a MaterializedCte with a struct literal or struct update skips the scan check in try_new. Private fields send every new node through try_new, and every in-place change through inputs_mut or with_new_inputs. The fields are pub(crate), so the tree-node and display code of datafusion-expr is unchanged. inputs_mut and into_inputs replace the remaining direct field access in the optimizer and the physical planner.
bdf3a4d to
ffb77b4
Compare
|
|
||
| /// The body and the continuation, in this order, for a rule that changes | ||
| /// them in place. The schemas of the scans are not checked again. | ||
| pub fn inputs_mut(&mut self) -> (&mut Arc<LogicalPlan>, &mut Arc<LogicalPlan>) { |
There was a problem hiding this comment.
Could we replace inputs_mut with a fallible closure-based try_map_inputs_mut and make with_new_inputs return Result<Self>? Both can remain unchecked for now, but these signatures would permit future validation.
| The fields of `MaterializedCte` are private. Read them with | ||
| `MaterializedCte::id`, `name`, `body` and `continuation`. Build a node with | ||
| `MaterializedCte::try_new`, which checks the scans of the CTE. A rule that | ||
| changes the inputs in place can use `MaterializedCte::inputs_mut` or |
There was a problem hiding this comment.
Nit: with_new_inputs returns a new node rather than modifying inputs in place. Please distinguish it from the in-place mutation API and document which paths validate scans.
|
|
||
| /// The body and the continuation, in this order. Build a node again with | ||
| /// [`Self::try_new`]. | ||
| pub fn into_inputs(self) -> (Arc<LogicalPlan>, Arc<LogicalPlan>) { |
There was a problem hiding this comment.
Optional: could into_parts return the ID, name, body, and continuation? Current callers copy the name before consuming the node. Moving all four values would simplify reconstruction.
Review asked that the unchecked mutation APIs keep room for future validation. try_map_inputs_mut replaces inputs_mut and takes a fallible closure, and with_new_inputs returns a Result. into_parts replaces into_inputs and also returns the id and name, so that callers do not copy the name before they consume the node. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thanks for helping review this @kosiew. I've been mulling over this change, I think it's in the right direction, but I wonder if there isn't a better path (which we could do instead of this or as a followup): #27725. Basically thinking along the lines of how can we make bad states unrepresentable / eliminate foootguns. Would love to get some high level thoughts from you on the best way to handle these complex relationships between plans and optimizers, and if we should merge this now and work on followups or if there is any reason to pause and look at the bigger picture. |
Which issue does this PR close?
Follow-up to #26274. This PR is stacked on it: only the last commit belongs to this PR. Review #26274 first.
Rationale for this change
#26274 makes the
schemaandprojectionfields ofMaterializedCteScanprivate, so that they always match. TheMaterializedCtenode still has public fields. A rule that builds the node with a struct literal or a struct update skips the scan check inMaterializedCte::try_new.What changes are included in this PR?
MaterializedCtearepub(crate). Downstream code reads them throughid(),name(),body()andcontinuation().MaterializedCte::inputs_mutandMaterializedCte::into_inputsreplace the direct field access in the optimizer driver,TypeCoercion,DecorrelatePredicateSubquery,PushDownFilter,OptimizeProjectionsand the physical planner.try_new, so the scans are checked.Are these changes tested?
Yes, by the existing tests. The change does not change behavior.
Are there any user-facing changes?
Yes. This is a breaking API change, which the 57.0.0 upgrade guide describes.