Skip to content

GH-55948: [C++][Dataset][Parquet] Preserve signed-zero bounds in predicate pushdown - #55954

Open
valleysonata wants to merge 3 commits into
apache:mainfrom
valleysonata:fix/parquet-signed-zero-pushdown
Open

valleysonata wants to merge 3 commits into
apache:mainfrom
valleysonata:fix/parquet-signed-zero-pushdown

Conversation

@valleysonata

@valleysonata valleysonata commented Dec 4, 2026 •

Copy link
Copy Markdown

Closes #55948.

Rationale

Parquet statistics can store a minimum of -0.0 and a maximum of +0.0 for a row group containing positive zeros. Treating those bounds as a single value lets filter simplification substitute negative zero and incorrectly skip matching rows.

Changes

Distinguish the signs of zero when deciding whether the bounds represent a single value. If the signs differ, retain the range guarantee. Add a regression test for a reciprocal filter on a row group containing positive zero.

Tests

All 61 tests in arrow-dataset-file-parquet-test passed, including the new regression in threaded and serial scans. A separate focused check showed the original code simplified the predicate to false; the fix preserves the predicate.

User-facing changes

Critical Fix: Sign-sensitive Parquet filters no longer drop matching rows in this case. No API changes.

Was AI used for this PR?

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

AI helped prepare the patch, regression test, and description. The contributor reviewed the patch.

Do not turn Parquet bounds spanning both signs of zero into a single-value guarantee.
Check that a reciprocal filter retains a Parquet row group containing +0.0.
Comment thread cpp/src/arrow/dataset/file_parquet.cc Outdated
Comment on lines +377 to +379
// Floating-point bounds can span -0.0 and +0.0. A single-value guarantee
// would let filter simplification substitute one sign for both.
if (min->Equals(*max, EqualOptions::Defaults().signed_zeros_equal(false))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 The goal here is to prevent filter simplification from substituting a specific zero sign into sign-sensitive expressions, while still respecting Parquet TYPE_ORDER statistics and keeping row-group pruning intact.

Checking signed_zeros_equal(false) here has two drawbacks:

  1. Under Parquet's TYPE_ORDER reader rules, min = +0.0, max = +0.0 can still contain -0.0 (and min = -0.0, max = -0.0 can still contain +0.0). Because parquet-cpp decodes min/max verbatim on read, those files would still hit this branch and substitute the wrong zero sign.
  2. Falling through to the range guarantee x >= -0.0 and x <= +0.0 drops pruning for x != 0.0, drops the TryCountRows fast path for x == 0.0, and disables pruning altogether on nullable all-zero row groups (since Inequality::ExtractOne doesn't unwrap or_(and_(...), is_null(x))).

A more minimal fix at the root cause is to leave EvaluateStatisticsAsExpression unchanged and handle this in SimplifyWithGuarantee (cpp/src/arrow/compute/expression.cc): skip moving equal(field_ref, literal) into known_values when the literal is a floating-point zero, leaving it in conjunction_members. Inequality::ExtractOne already handles Comparison::EQUAL, so:

  • sign-sensitive expressions (1.0 / x > 0, cast(x, utf8) == "0", etc.) are never substituted,
  • comparison/null/set-lookup simplifications (x == 0.0, x != 0.0, x > 0.0, is_null(x)) and nullable pruning keep working,
  • ExtractKnownFieldValues continues to work for partition column materialization, and
  • all Parquet zero-bound pairs (-0/+0, +0/+0, -0/-0) and non-Parquet callers are covered in one place.

Comment on lines +810 to +820
TEST_P(TestParquetFileFormatScan, PredicatePushdownPreservesSignedZero) {
auto table = TableFromJSON(schema({field("x", float64())}), {R"([{"x": 0.0}])"});
TableBatchReader reader(*table);
auto source = GetFileSource(&reader);

SetSchema(reader.schema()->fields());
ASSERT_OK_AND_ASSIGN(auto fragment, format_->MakeFragment(*source));

auto reciprocal = compute::call("divide", {literal(1.0), field_ref("x")});
CountRowGroupsInFragment(fragment, {0}, greater(std::move(reciprocal), literal(0.0)));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 To verify both correctness across zero-bound representations and that pruning/row counting don't regress, consider adding coverage for:

  • SimplifyWithGuarantee directly (in expression_test.cc) with equal(x, ±0.0): sign-sensitive expressions (divide(1.0, x) > 0, cast(x, utf8()) == "0") stay unsimplified, while comparisons (x == 0.0, x != 0.0, x > 0.0) still simplify.
  • EncodedStatistics with min = +0.0, max = +0.0 (the TYPE_ORDER compatibility case) and TryCountRows with a sign-sensitive filter (e.g., 1.0 / x < 0.0 returning 0 on [+0.0] and x == 0.0 returning 1).
  • A nullable [0.0, null] row group still pruning x > 1.0.

@rok

rok commented Dec 4, 2026

Copy link
Copy Markdown
Member

@valleysonata thanks for working on this! Please see comment and try to resolve issue there. Also keep in mind we don't have enough reviewer capacity on the project to supplement your understanding of the problem. :)

Signed-off-by: Adyaraka Banyu Langit <222337788+valleysonata@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants