ivan-kiselev opened a new issue, #27946:
URL: https://github.com/apache/datafusion/issues/27946

   ### Describe the bug
   
   Leaf projection splitting changes the argument field name seen by 
`arrow_field` from `value` to `__datafusion_leaf_0`. The result depends on the 
physical plan: one partition returns the expected name, while four partitions 
return the synthetic alias. Numeric results are unchanged.
   
   We are already working on a solution and plan to contribute a fix with 
regression coverage. The fix needs to preserve argument fields for field-aware 
UDFs generally, not special-case `arrow_field`.
   
   ### To reproduce
   
   Reproduced on untouched Apache DataFusion main at 
018d099cd992f998c26a39e9f086e375e286a1ec, using Rust 1.99.1 and the unchanged 
Cargo.lock. No downstream changes or additional data sources are required. Use 
a fresh output path:
   
   ```sql
   COPY (
     SELECT column1 AS id, column2 AS s FROM VALUES
       (1, {value: 100}), (2, {value: 200}), (3, {value: 150}),
       (4, {value: 300}), (5, {value: 250})
   ) TO 'leaf_name_repro.parquet' STORED AS PARQUET;
   CREATE EXTERNAL TABLE leaf_name_repro STORED AS PARQUET
   LOCATION 'leaf_name_repro.parquet';
   SET datafusion.execution.batch_size = 2;
   SET datafusion.execution.target_partitions = 1;
   SELECT arrow_field(s['value'])['name'], id + 1 FROM leaf_name_repro;
   SET datafusion.execution.target_partitions = 4;
   SELECT arrow_field(s['value'])['name'], id + 1 FROM leaf_name_repro;
   ```
   
   ### Expected behavior
   
   Both queries should return the row set `(value, 2)` through `(value, 6)`. 
The second instead returns `(__datafusion_leaf_0, 2)` through 
`(__datafusion_leaf_0, 6)`.
   
   ### Additional context
   
   The rewrite was introduced in #27152, commit 
4c430b44b4c25c39737e0266ab193fff40e9f7fd. `try_split_leaf_projection` extracts 
`get_field(s, 'value')` into a lower projection with a synthetic alias. 
`rewrite_outer_expr` replaces the expression with a `Column` referencing that 
alias. `ScalarFunctionExpr::evaluate` derives argument fields from the 
rewritten children, so `arrow_field` observes the synthetic name.
   
   Four partitions and batch size 2 introduce the round-robin repartition that 
triggers the split. This is plan-dependent, not a race. Final output schema 
checks do not catch a changed argument field name.
   
   Related work: #25329 concerns duplicate evaluation; #27776 and #27867 
concern pruning; #27925 concerns ordering, constants and equalities. This 
regression reproduces on main without either open PR.
   
   ### Willingness to contribute
   
   I plan to contribute a fix for this bug independently.
   


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