Skip to content

Commit 801bb0e

Browse files
committed
docs: clarify struct-cast rewrite invariants
Document the traversal order, per-rewrite lifetime, and retained Arc ownership required by generated-cast tracking, including why provenance stays local. Explain how retaining only the selected cast-target path avoids sibling conversions while preserving the all-null Struct shortcut.
1 parent 1717bb1 commit 801bb0e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

‎datafusion/physical-expr-adapter/src/schema_rewriter.rs‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,12 @@ impl PhysicalExprAdapter for DefaultPhysicalExprAdapter {
272272
struct DefaultPhysicalExprAdapterRewriter {
273273
logical_file_schema: SchemaRef,
274274
physical_file_schema: SchemaRef,
275-
// Retain generated casts so their pointer identity remains reliable even
276-
// after a wider cast has been removed from the expression tree.
275+
// A fresh map is created for each `rewrite()` call. Tracking relies on
276+
// bottom-up `transform` traversal: a generated child cast is recorded before
277+
// its parent `get_field` sees the same Arc allocation. Owned Arc clones keep
278+
// recorded allocations alive even after removal from the tree, preventing
279+
// pointer-address reuse. Keeping provenance here avoids adding markers to
280+
// expression types or threading it through rewrite results.
277281
generated_struct_casts: HashMap<*const (), Arc<dyn PhysicalExpr>>,
278282
}
279283

@@ -313,7 +317,9 @@ fn resolve_field_path<'a>(
313317
}
314318
}
315319

316-
/// Retain a field path without changing its ancestors' metadata or nullability.
320+
/// Retain only the selected field path in a cast target, preserving its Struct
321+
/// ancestors' metadata and nullability. This excludes unselected sibling
322+
/// conversions while keeping the all-null Struct shortcut for decimal casts.
317323
fn retain_field_path(field: &FieldRef, path: &[&str]) -> Option<FieldRef> {
318324
let Some((name, rest)) = path.split_first() else {
319325
return Some(Arc::clone(field));

0 commit comments

Comments
 (0)