Skip to content

[C++][Dataset][Parquet] Row group of +0.0 values is skipped: statistics (-0.0, +0.0) become the guarantee x == -0.0 #55948

Backlog

Description

@zhaohaisun

Describe the bug, including details regarding any error messages, version, and platform.

For a float column whose row group contains only 0.0, the Parquet writer stores min = -0.0 and max = +0.0 (as the Parquet spec asks). The dataset reader turns this into the guarantee x == -0.0 and folds the filter with x = -0.0. Filters that distinguish the sign of zero are then evaluated for the wrong value, and the row group is skipped.

import pyarrow as pa, pyarrow.parquet as pq, pyarrow.dataset as ds, pyarrow.compute as pc

t = pa.table({"x": pa.array([0.0, 0.0])})
pq.write_table(t, "with_stats.parquet")
pq.write_table(t, "no_stats.parquet", write_statistics=False)
print(pq.ParquetFile("with_stats.parquet").metadata.row_group(0).column(0).statistics)  # min: -0.0, max: 0.0

x = pc.field("x")
for e in [pc.divide(pc.scalar(1.0), x) > pc.scalar(0.0),   # 1/0.0 = +inf
          x.cast(pa.string()) == pc.scalar("0")]:
    print(t.filter(e).num_rows,                                           # 2
          ds.dataset("no_stats.parquet").to_table(filter=e).num_rows,     # 2
          ds.dataset("with_stats.parquet").to_table(filter=e).num_rows)   # 0

Cause, from reading the code: ParquetFileFragment::EvaluateStatisticsAsExpression (cpp/src/arrow/dataset/file_parquet.cc) checks min->Equals(*max), which treats -0.0 and +0.0 as equal, and then returns equal(field, literal(min)), i.e. x == -0.0. SimplifyWithGuarantee replaces x with the known value -0.0, so 1/x > 0 folds to -inf > 0 = false and cast(x, string) == "0" folds to "-0" == "0" = false.

A possible fix: emit the single-value guarantee only when min and max are bitwise identical, and use the range guarantee x >= min and x <= max otherwise (comparisons are unaffected because -0.0 == +0.0).

Related but different: GH-46183 / GH-54915 (is_in and index_in hashing -0.0 and +0.0 differently). Here the problem is the known-value substitution from statistics, and it also affects arithmetic and casts.

Reproduces on pyarrow 10.0.1, 16.1.0, 20.0.0 and 26.0.1 (Linux x86_64, Python 3.11). The code is unchanged on main.

Component(s)

C++, Parquet, Python

Drafted with Claude Code; reproduced and reviewed by me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions