adriangb opened a new issue, #19336:
URL: https://github.com/apache/datafusion/issues/19336

   ## Describe the bug
   
   The `first_value` and `last_value` aggregate functions do not preserve Field 
metadata from their input arguments. When a column has metadata attached to it, 
using `first_value()` or `last_value()` on that column results in the metadata 
being lost in the output.
   
   This also affects `DISTINCT ON` queries since they use `first_value` 
internally.
   
   ## To Reproduce
   
   ```sql
   -- Assuming a table with a column that has metadata attached
   SELECT first_value(id), get_metadata(first_value(id), 'metadata_key')
   FROM table_with_metadata;
   
   -- The metadata is lost (returns NULL instead of the expected metadata value)
   ```
   
   ## Expected behavior
   
   The `first_value` and `last_value` functions should preserve the Field 
metadata from their input argument, similar to how other operations preserve 
metadata.
   
   ## Additional context
   
   The fix requires implementing the `return_field()` method for both 
`FirstValue` and `LastValue` aggregate UDFs to copy the metadata from the input 
field to the output field.
   
   ---
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   Co-Authored-By: Claude Opus 4.5 <[email protected]>


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