-
Notifications
You must be signed in to change notification settings - Fork 4.3k
GH-50689: [C++][Parquet] Add IEEE-754 total order and nan count for floating types #50807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HuaHuaY
wants to merge
1
commit into
apache:main
Choose a base branch
from
HuaHuaY:nan_count
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,7 @@ | |
| #include "arrow/dataset/scanner.h" | ||
| #include "arrow/filesystem/path_util.h" | ||
| #include "arrow/table.h" | ||
| #include "arrow/type_traits.h" | ||
| #include "arrow/util/checked_cast.h" | ||
| #include "arrow/util/future.h" | ||
| #include "arrow/util/iterator.h" | ||
|
|
@@ -370,7 +371,7 @@ std::optional<compute::Expression> ParquetFileFragment::EvaluateStatisticsAsExpr | |
| const parquet::Statistics& statistics) { | ||
| auto field_expr = compute::field_ref(field_ref); | ||
|
|
||
| bool may_have_null = !statistics.HasNullCount() || statistics.null_count() > 0; | ||
| bool may_have_null = !statistics.HasNullCount() || statistics.null_count() != 0; | ||
| // Optimize for corner case where all values are nulls | ||
| if (statistics.num_values() == 0) { | ||
| // If there are no non-null values, column `field_ref` in the fragment | ||
|
|
@@ -379,6 +380,31 @@ std::optional<compute::Expression> ParquetFileFragment::EvaluateStatisticsAsExpr | |
| return is_null(std::move(field_expr)); | ||
| } | ||
|
|
||
| auto with_null = [&](compute::Expression expression) { | ||
| if (may_have_null) { | ||
| return compute::or_(std::move(expression), is_null(field_expr)); | ||
| } | ||
| return expression; | ||
| }; | ||
| auto is_nan_expression = [&] { return compute::call("is_nan", {field_expr}); }; | ||
|
|
||
| const bool is_floating_point = is_floating(field.type()->id()); | ||
| const auto nan_count = statistics.nan_count(); | ||
| const bool all_nan = | ||
| is_floating_point && nan_count.has_value() && *nan_count == statistics.num_values(); | ||
| if (all_nan) { | ||
| return with_null(is_nan_expression()); | ||
| } | ||
|
|
||
| if (field.type()->id() == Type::HALF_FLOAT) { | ||
| // TODO: Arrow compute has no HALF_FLOAT scalar comparison kernels, so numeric | ||
| // statistics expressions cannot be bound. GH-46858 tracks the scalar | ||
| // representation, while GH-50512 explains why HALF_FLOAT cannot simply be | ||
| // added to NumericTypes(). Statistics pruning is optional, so skip it instead | ||
| // of returning NotImplemented and failing the scan. | ||
| return std::nullopt; | ||
| } | ||
|
|
||
| std::shared_ptr<Scalar> min, max; | ||
| if (!StatisticsAsScalars(statistics, &min, &max).ok()) { | ||
| return std::nullopt; | ||
|
|
@@ -393,10 +419,10 @@ std::optional<compute::Expression> ParquetFileFragment::EvaluateStatisticsAsExpr | |
| if (min->Equals(*max)) { | ||
| auto single_value = compute::equal(field_expr, compute::literal(std::move(min))); | ||
|
|
||
| if (!may_have_null) { | ||
| return single_value; | ||
| if (is_floating_point && (!nan_count.has_value() || *nan_count != 0)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: suggest creating a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or perhaps even a |
||
| single_value = compute::or_(std::move(single_value), is_nan_expression()); | ||
| } | ||
| return compute::or_(std::move(single_value), is_null(std::move(field_expr))); | ||
| return with_null(std::move(single_value)); | ||
| } | ||
|
|
||
| auto lower_bound = compute::greater_equal(field_expr, compute::literal(min)); | ||
|
|
@@ -419,10 +445,10 @@ std::optional<compute::Expression> ParquetFileFragment::EvaluateStatisticsAsExpr | |
| } else { | ||
| in_range = compute::and_(std::move(lower_bound), std::move(upper_bound)); | ||
| } | ||
| if (may_have_null) { | ||
| return compute::or_(std::move(in_range), compute::is_null(std::move(field_expr))); | ||
| if (is_floating_point && (!nan_count.has_value() || *nan_count != 0)) { | ||
| in_range = compute::or_(std::move(in_range), is_nan_expression()); | ||
| } | ||
| return in_range; | ||
| return with_null(std::move(in_range)); | ||
| } | ||
| return std::nullopt; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this because I added a
PARQUET_DEPRECATEDatcpp/src/parquet/statistics.hand ci failed. https://github.com/apache/arrow/actions/runs/30975844655/job/92209544482I believe this is a long-standing issue. If someone would like me to submit a separate PR to fix it, I can certainly do so.