adriangb opened a new pull request, #22372:
URL: https://github.com/apache/datafusion/pull/22372

   ## Which issue does this PR close?
   
   - No separate issue. This addresses a review observation from #22026: 
https://github.com/apache/datafusion/pull/22026#discussion_r3267880296
   
   ## Rationale for this change
   
   `TableSchema::with_table_partition_cols` appends to an existing 
partition-column list via `Arc::get_mut(...).expect(...)`. The `expect` message 
assumes that owning `self` implies sole ownership of the inner 
`Arc<Vec<FieldRef>>` — but that is not true. `TableSchema` derives `Clone`, and 
cloning only bumps the `Arc` refcount without copying the `Vec`.
   
   So this sequence panics today:
   
   ```rust
   let ts = TableSchema::new(file_schema, vec![some_partition_col]);
   let cloned = ts.clone();                       // Arc refcount is now 2
   let _ = cloned.with_table_partition_cols(more); // Arc::get_mut -> None -> 
expect() panics
   ```
   
   `with_table_partition_cols` taking `mut self` gives unique ownership of the 
*struct*, not of the inner `Arc`.
   
   ## What changes are included in this PR?
   
   - Replace `Arc::get_mut(...).expect(...)` with `Arc::make_mut(...)`, which 
mutates in place when the `Arc` is uniquely owned and copy-on-writes when it is 
shared. This also removes the empty/non-empty branch, since `make_mut` handles 
both cases.
   
   ## Are these changes tested?
   
   Yes — added `test_with_table_partition_cols_after_clone_does_not_panic`, 
which clones a `TableSchema` and appends partition columns to the clone, 
verifying it does not panic and that the other clone is left unmodified 
(copy-on-write isolation). Existing `TableSchema` tests continue to pass.
   
   ## Are there any user-facing changes?
   
   No API changes. The only observable difference is that a previously 
panicking call path now succeeds.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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]

Reply via email to