-
Notifications
You must be signed in to change notification settings - Fork 106
fix(expr): correct CanContainNulls/CanContainNaNs when field missing from stats map #686
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -436,18 +436,39 @@ class StrictMetricsVisitor : public BoundVisitor<bool> { | |
| } | ||
|
|
||
| bool CanContainNulls(int32_t id) { | ||
| auto field_result = schema_.GetFieldById(id); | ||
| if (field_result.has_value() && field_result->has_value() && | ||
| !field_result->value().get().optional()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (data_file_.null_value_counts.empty()) { | ||
| return true; | ||
| } | ||
| auto it = data_file_.null_value_counts.find(id); | ||
| return it != data_file_.null_value_counts.cend() && it->second > 0; | ||
| if (it == data_file_.null_value_counts.cend()) { | ||
| return true; | ||
| } | ||
| return it->second > 0; | ||
| } | ||
|
|
||
| bool CanContainNaNs(int32_t id) { | ||
| // nan counts might be null for early version writers when nan counters are not | ||
|
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. I think the original implementation matches the Java parity exactly, which assumes null_value_counts should populate all fields but nan_value_counts don't (when they are not empty). I agree current PR is a nice fix. I still suggest keeping this comment since it still holds. |
||
| // populated. | ||
| auto field_result = schema_.GetFieldById(id); | ||
| if (field_result.has_value() && field_result->has_value()) { | ||
| auto type_id = field_result->value().get().type()->type_id(); | ||
| if (type_id != TypeId::kFloat && type_id != TypeId::kDouble) { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| if (data_file_.nan_value_counts.empty()) { | ||
| return true; | ||
| } | ||
| auto it = data_file_.nan_value_counts.find(id); | ||
| return it != data_file_.nan_value_counts.cend() && it->second > 0; | ||
| if (it == data_file_.nan_value_counts.cend()) { | ||
| return true; | ||
| } | ||
| return it->second > 0; | ||
| } | ||
|
|
||
| bool ContainsNullsOnly(int32_t id) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -846,4 +846,50 @@ TEST_F(StrictMetricsEvaluatorMigratedTest, EvaluateOnNestedColumnWithStats) { | |
| ExpectShouldRead(Expressions::NotNull("struct.nested_col_with_stats"), false); | ||
| } | ||
|
|
||
| TEST_F(StrictMetricsEvaluatorMigratedTest, MissingNullCountForField) { | ||
|
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. This is not migrated from Java implementation so please do not use this confusing name. |
||
| // Field 14 (no_nan_stats, float64, optional) has bounds and value_counts but is | ||
| // missing from null_value_counts. The evaluator must conservatively assume nulls | ||
| // may exist and return kRowsMightNotMatch for comparison operators. | ||
| auto data_file = std::make_shared<DataFile>(); | ||
| data_file->file_path = "null_test.parquet"; | ||
| data_file->file_format = FileFormatType::kParquet; | ||
| data_file->record_count = 50; | ||
| data_file->value_counts = {{14, 50L}}; | ||
| data_file->null_value_counts = {{4, 0L}, {5, 0L}}; | ||
| data_file->nan_value_counts = {{14, 0L}}; | ||
| data_file->lower_bounds = {{14, Literal::Double(1.0).Serialize().value()}}; | ||
| data_file->upper_bounds = {{14, Literal::Double(100.0).Serialize().value()}}; | ||
|
|
||
| ExpectShouldRead(Expressions::LessThan("no_nan_stats", Literal::Double(200.0)), false, | ||
| data_file); | ||
| ExpectShouldRead(Expressions::LessThanOrEqual("no_nan_stats", Literal::Double(200.0)), | ||
| false, data_file); | ||
| ExpectShouldRead(Expressions::GreaterThan("no_nan_stats", Literal::Double(-1.0)), false, | ||
| data_file); | ||
| ExpectShouldRead(Expressions::GreaterThanOrEqual("no_nan_stats", Literal::Double(-1.0)), | ||
| false, data_file); | ||
| ExpectShouldRead(Expressions::Equal("no_nan_stats", Literal::Double(50.0)), false, | ||
| data_file); | ||
| } | ||
|
wgtmac marked this conversation as resolved.
|
||
|
|
||
| TEST_F(StrictMetricsEvaluatorMigratedTest, MissingNanCountForField) { | ||
| // Field 14 (no_nan_stats, float64, optional) is missing from nan_value_counts. | ||
| // For a floating-point field, the evaluator must conservatively assume NaNs may | ||
| // exist and return kRowsMightNotMatch for comparison operators. | ||
| auto data_file = std::make_shared<DataFile>(); | ||
| data_file->file_path = "nan_test.parquet"; | ||
| data_file->file_format = FileFormatType::kParquet; | ||
| data_file->record_count = 50; | ||
| data_file->value_counts = {{14, 50L}}; | ||
| data_file->null_value_counts = {{14, 0L}}; | ||
| data_file->nan_value_counts = {{8, 0L}}; | ||
| data_file->lower_bounds = {{14, Literal::Double(1.0).Serialize().value()}}; | ||
| data_file->upper_bounds = {{14, Literal::Double(100.0).Serialize().value()}}; | ||
|
|
||
| ExpectShouldRead(Expressions::LessThan("no_nan_stats", Literal::Double(200.0)), false, | ||
| data_file); | ||
| ExpectShouldRead(Expressions::GreaterThan("no_nan_stats", Literal::Double(-1.0)), false, | ||
| data_file); | ||
| } | ||
|
|
||
| } // namespace iceberg | ||
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.
We should preserve error returned by
schema_.GetFieldById, so we need to change the return type toResult<bool>. BTW, why callingGetFieldByIdinstead ofFindFieldById? They are semantically different.