Skip to content

max() drops field metadata / extension type from its result (first_value keeps it) #26916

Closed

Description

@adriangb

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

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:

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: #21981 (MinAccumulator dropping inner-field metadata for lists).

Activity

  1. rishiiicreates commented on Oct 30, 2026

    @rishiiicreates

    i can take this, will add return_field to Max and Min to preserve input field metadata and add tests in metadata.slt

  2. cblp commented on Oct 30, 2026

    @cblp
    Contributor

    take

  3. adriangb commented on Nov 2, 2026

    @adriangb
    ContributorAuthor

    I looked at #26938 and #26939, both opened around the same time. I'd reviewed #26938 but after looking at #26939 I think #26939 looks better. @rishiiicreates could we close #26938 and focus review effort on #26939?

  4. added a commit that references this issue on Nov 2, 2026
    9411463
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions