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

   ### Describe the bug
   
   `max()` (and likely `min()`) drops field metadata, including Arrow extension 
types, from its result. `first_value()` keeps it, so aggregates are 
inconsistent.
   
   Found while reviewing https://github.com/apache/datafusion/pull/21714. 
Reproduces on `main` with any metadata-carrying column (e.g. 
`table_with_metadata` in `metadata.slt`), so it predates that PR.
   
   ### To Reproduce
   
   On #21714:
   
   ```sql
   CREATE TABLE u (id UUID);
   INSERT INTO u VALUES (X'00010203040506070809000102030506');
   
   SELECT arrow_metadata(max(id), 'ARROW:extension:name') FROM u;          -- 
NULL
   SELECT arrow_metadata(first_value(id), 'ARROW:extension:name') FROM u;  -- 
arrow.uuid
   ```
   
   On `main`, in `metadata.slt`:
   
   ```sql
   SELECT arrow_metadata(max(id), 'metadata_key') FROM table_with_metadata;     
     -- NULL
   SELECT arrow_metadata(first_value(id), 'metadata_key') FROM 
table_with_metadata;  -- the id field
   ```
   
   ### Expected behavior
   
   `max` / `min` return a value of the same type as their input, so the result 
field should keep the input's metadata (as `first_value` does).
   
   For comparison, DuckDB: `typeof(max(uuid_col))` is `UUID` and 
`typeof(max(json_col))` is `JSON`.
   
   ### Additional context
   
   Related: https://github.com/apache/datafusion/issues/21981 (`MinAccumulator` 
dropping inner-field metadata for lists).
   


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