Skip to content

CAST statistics can produce incorrect MIN/MAX results #25221

Closed

Description

@haohuaijin

Describe the bug

Casting string min/max statistics to integers does not preserve their ordering. Aggregate optimization can therefore return incorrect results.

To Reproduce

SET datafusion.execution.target_partitions = 1;
SET datafusion.execution.collect_statistics = true;

COPY (SELECT * FROM (VALUES ('1'), ('100'), ('2')) AS t(a))
TO '/tmp/cast_statistics.parquet' STORED AS PARQUET;

CREATE EXTERNAL TABLE t STORED AS PARQUET
LOCATION '/tmp/cast_statistics.parquet';

SELECT MIN(CAST(a AS INT)), MAX(CAST(a AS INT)) FROM t;

Actual: 1, 2. Expected: 1, 100. The same issue occurs with BIGINT.

Expected behavior

Only propagate CAST statistics when the conversion is proven safe for the supplied bounds.

Additional context

found this when work on #25220

Activity

  1. added theissue type on Sep 12, 2026
  2. haohuaijin commented on Sep 12, 2026

    @haohuaijin
    ContributorAuthor

    take

  3. added a commit that references this issue on Sep 19, 2026
    ccfe704
  4. added a commit that references this issue on Sep 27, 2026
    9ff4bf5
  5. added a commit that references this issue on Oct 11, 2026
    abf1e6e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions