rok commented on code in PR #55954:
URL: https://github.com/apache/arrow/pull/55954#discussion_r4803748435
##########
cpp/src/arrow/dataset/file_parquet.cc:
##########
@@ -373,7 +374,9 @@ std::optional<compute::Expression>
ParquetFileFragment::EvaluateStatisticsAsExpr
min = maybe_min.MoveValueUnsafe().scalar();
max = maybe_max.MoveValueUnsafe().scalar();
- if (min->Equals(*max)) {
+ // 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)))
{
Review Comment:
:robot: 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.
##########
cpp/src/arrow/dataset/file_parquet_test.cc:
##########
@@ -807,6 +807,18 @@ TEST_P(TestParquetFileFormatScan,
ExplicitRowGroupSelection) {
scan_status);
}
+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)));
+}
Review Comment:
:robot: 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`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]