Repository navigation
GH-55948: [C++][Dataset][Parquet] Preserve signed-zero bounds in predicate pushdown - #55954
valleysonata wants to merge 3 commits into
Conversation
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.
| // 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))) { |
There was a problem hiding this comment.
🤖 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:
- Under Parquet's
TYPE_ORDERreader rules,min = +0.0, max = +0.0can still contain-0.0(andmin = -0.0, max = -0.0can still contain+0.0). Becauseparquet-cppdecodesmin/maxverbatim on read, those files would still hit this branch and substitute the wrong zero sign. - Falling through to the range guarantee
x >= -0.0 and x <= +0.0drops pruning forx != 0.0, drops theTryCountRowsfast path forx == 0.0, and disables pruning altogether on nullable all-zero row groups (sinceInequality::ExtractOnedoesn't unwrapor_(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, ExtractKnownFieldValuescontinues 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.
| 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))); | ||
| } |
There was a problem hiding this comment.
🤖 To verify both correctness across zero-bound representations and that pruning/row counting don't regress, consider adding coverage for:
SimplifyWithGuaranteedirectly (inexpression_test.cc) withequal(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.EncodedStatisticswithmin = +0.0, max = +0.0(theTYPE_ORDERcompatibility case) andTryCountRowswith a sign-sensitive filter (e.g.,1.0 / x < 0.0returning0on[+0.0]andx == 0.0returning1).- A nullable
[0.0, null]row group still pruningx > 1.0.
|
@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>
Closes #55948.
Rationale
Parquet statistics can store a minimum of
-0.0and a maximum of+0.0for 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-testpassed, including the new regression in threaded and serial scans. A separate focused check showed the original code simplified the predicate tofalse; 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:
Reviewed before submission by:
AI helped prepare the patch, regression test, and description. The contributor reviewed the patch.