-
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
6
commits 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
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb6f9f7
Add IEEE-754 total order and nan count for floating types
HuaHuaY 3546b00
address review
HuaHuaY 129b2bb
address review
HuaHuaY 779ef07
use overload instead of api breaking changes
HuaHuaY 295a14a
address review
HuaHuaY ad1a6e5
upgrade parquet-testing
HuaHuaY 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
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 |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| #include "arrow/testing/util.h" | ||
| #include "arrow/type.h" | ||
| #include "arrow/type_fwd.h" | ||
| #include "arrow/util/float16.h" | ||
| #include "arrow/util/io_util.h" | ||
| #include "arrow/util/logging_internal.h" | ||
| #include "arrow/util/range.h" | ||
|
|
@@ -921,7 +922,7 @@ TEST(TestParquetStatistics, NullMax) { | |
| auto statistics = reader->RowGroup(0)->metadata()->ColumnChunk(0)->statistics(); | ||
| auto stat_expression = | ||
| ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *statistics); | ||
| EXPECT_EQ(stat_expression->ToString(), "(x >= 1)"); | ||
| EXPECT_EQ(stat_expression->ToString(), "((x >= 1) or is_nan(x))"); | ||
| } | ||
|
|
||
| TEST(TestParquetStatistics, NoNullCount) { | ||
|
|
@@ -974,6 +975,95 @@ TEST(TestParquetStatistics, NoNullCount) { | |
| } | ||
| } | ||
|
|
||
| template <typename T> | ||
| void TestNaNCount(const std::shared_ptr<DataType>& type, | ||
| const ::parquet::schema::NodePtr& parquet_node) { | ||
| auto field = ::arrow::field("x", type); | ||
| auto dataset_schema = ::arrow::schema({field}); | ||
| ::parquet::ColumnDescriptor descr(parquet_node, 0, 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. These test cases still use type_defined_order and do not cover the new ieee754 total order and do not actually test the filtering logic. Does it make sense to directly use |
||
| auto encode = [](T value) { | ||
| return std::string(reinterpret_cast<const char*>(&value), sizeof(value)); | ||
| }; | ||
| auto check_expression = [&](const std::optional<compute::Expression>& expression, | ||
| const char* expected) { | ||
| ASSERT_TRUE(expression.has_value()); | ||
| EXPECT_EQ(expected, expression->ToString()); | ||
| ASSERT_OK(expression->Bind(*dataset_schema)); | ||
| }; | ||
|
|
||
| ::parquet::EncodedStatistics encoded_stats; | ||
| encoded_stats.set_min(encode(T{1})).set_max(encode(T{100})).set_null_count(0); | ||
| auto stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 10); | ||
| auto expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| check_expression(expression, "(((x >= 1) and (x <= 100)) or is_nan(x))"); | ||
|
|
||
| encoded_stats.set_nan_count(0); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 10); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| check_expression(expression, "((x >= 1) and (x <= 100))"); | ||
|
|
||
| encoded_stats.set_nan_count(2); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 10); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| check_expression(expression, "(((x >= 1) and (x <= 100)) or is_nan(x))"); | ||
|
|
||
| encoded_stats.set_null_count(1); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 10); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| check_expression(expression, | ||
| "((((x >= 1) and (x <= 100)) or is_nan(x)) or " | ||
| "is_null(x, {nan_is_null=false}))"); | ||
|
|
||
| encoded_stats.set_null_count(0); | ||
| encoded_stats.ClearMinMax(); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 2); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| check_expression(expression, "is_nan(x)"); | ||
| } | ||
|
|
||
| TEST(TestParquetStatistics, NaNCount) { | ||
| TestNaNCount<float>(float32(), | ||
| ::parquet::schema::Float("x", ::parquet::Repetition::REQUIRED)); | ||
| TestNaNCount<double>(float64(), | ||
| ::parquet::schema::Double("x", ::parquet::Repetition::REQUIRED)); | ||
| } | ||
|
|
||
| TEST(TestParquetStatistics, HalfFloatNaNCount) { | ||
| auto field = ::arrow::field("x", float16()); | ||
| auto parquet_node = ::parquet::schema::PrimitiveNode::Make( | ||
| "x", ::parquet::Repetition::REQUIRED, ::parquet::LogicalType::Float16(), | ||
| ::parquet::Type::FIXED_LEN_BYTE_ARRAY, 2); | ||
| ::parquet::ColumnDescriptor descr(parquet_node, 0, 0); | ||
| auto encode = [](util::Float16 value) { | ||
| const auto bytes = value.ToLittleEndian(); | ||
| return std::string(reinterpret_cast<const char*>(bytes.data()), bytes.size()); | ||
| }; | ||
|
|
||
| ::parquet::EncodedStatistics encoded_stats; | ||
| encoded_stats.set_min(encode(util::Float16(-1.0f))) | ||
| .set_max(encode(util::Float16(1.0f))) | ||
| .set_null_count(0) | ||
| .set_nan_count(1); | ||
| auto stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 3); | ||
| auto expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| ASSERT_FALSE(expression.has_value()); | ||
|
|
||
| encoded_stats.ClearMinMax(); | ||
| encoded_stats.set_nan_count(3); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 3); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| ASSERT_TRUE(expression.has_value()); | ||
| EXPECT_EQ("is_nan(x)", expression->ToString()); | ||
| ASSERT_OK(expression->Bind(*::arrow::schema({field}))); | ||
|
|
||
| encoded_stats.set_null_count(1); | ||
| stats = ::parquet::Statistics::Make(&descr, &encoded_stats, 3); | ||
| expression = ParquetFileFragment::EvaluateStatisticsAsExpression(*field, *stats); | ||
| ASSERT_TRUE(expression.has_value()); | ||
| EXPECT_EQ("(is_nan(x) or is_null(x, {nan_is_null=false}))", expression->ToString()); | ||
| ASSERT_OK(expression->Bind(*::arrow::schema({field}))); | ||
| } | ||
|
|
||
| TEST_F(TestParquetFileFormat, MultithreadedScanRegression) { | ||
| // GH-38438: This test is similar to MultithreadedScan, but it try to use self | ||
| // designed Executor and DelayedBufferReader to mock async execution to make | ||
|
|
||
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.