-
Notifications
You must be signed in to change notification settings - Fork 3k
ORC: Fix importing ORC files with float and double columns and test #3332
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
Merged
rdblue
merged 14 commits into
apache:master
from
kbendick:fix-importing-orc-files-double-float-metrics
Oct 29, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bfba1d9
WIP with included fixes so can hop to another branch
kbendick 6908f85
work on manually writing an ORC file to import
kbendick 7d05e0f
Test added in TestAddFileProcedure which causes the bug
kbendick 7b3c539
Fix max and have fully working tests after updating build file
kbendick fce4888
Remove unused preconditions import
kbendick cd195b0
Fix checkstyle missing leading space after commas
kbendick 8e04370
Remove unnecessary space
kbendick ddeeda7
Check if ORC is providing NaN for stats and reassign Iceberg stats to…
kbendick 1b9b181
Add note to update to move test file off of Iceberg schema
kbendick 4ec3448
Handle doubles that might be NaN and only check for NaN not strictly …
kbendick b41aeb5
Fix cyclomatic complexity style check errors
kbendick 2737c6b
Workaround cyclomatic complexity check via helper method instead of O…
kbendick 4898f93
Avoid unnecessary boxing and unboxing of primitive types
kbendick 6a3c966
Avoid double ternary and simplify
kbendick 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,7 +44,6 @@ | |
| import org.apache.iceberg.hadoop.HadoopInputFile; | ||
| import org.apache.iceberg.io.InputFile; | ||
| import org.apache.iceberg.mapping.NameMapping; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.ImmutableSet; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
| import org.apache.iceberg.types.Conversions; | ||
|
|
@@ -196,11 +195,17 @@ private static Optional<ByteBuffer> fromOrcMin(Type type, ColumnStatistics colum | |
| min = Math.toIntExact((long) min); | ||
| } | ||
| } else if (columnStats instanceof DoubleColumnStatistics) { | ||
| // since Orc includes NaN for upper/lower bounds of floating point columns, and we don't want this behavior, | ||
| // we have tracked metrics for such columns ourselves and thus do not need to rely on Orc's column statistics. | ||
| Preconditions.checkNotNull(fieldMetrics, | ||
| "[BUG] Float or double type columns should have metrics being tracked by Iceberg Orc writers"); | ||
| min = fieldMetrics.lowerBound(); | ||
| if (fieldMetrics != null) { | ||
| // since Orc includes NaN for upper/lower bounds of floating point columns, and we don't want this behavior, | ||
| // we have tracked metrics for such columns ourselves and thus do not need to rely on Orc's column statistics. | ||
| min = fieldMetrics.lowerBound(); | ||
| } else { | ||
| // imported files will not have metrics that were tracked by Iceberg, so fall back to the file's metrics. | ||
| min = replaceNaN(((DoubleColumnStatistics) columnStats).getMinimum(), Double.NEGATIVE_INFINITY); | ||
| if (type.typeId() == Type.TypeID.FLOAT) { | ||
| min = ((Double) min).floatValue(); | ||
kbendick marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| } else if (columnStats instanceof StringColumnStatistics) { | ||
| min = ((StringColumnStatistics) columnStats).getMinimum(); | ||
| } else if (columnStats instanceof DecimalColumnStatistics) { | ||
|
|
@@ -234,11 +239,17 @@ private static Optional<ByteBuffer> fromOrcMax(Type type, ColumnStatistics colum | |
| max = Math.toIntExact((long) max); | ||
| } | ||
| } else if (columnStats instanceof DoubleColumnStatistics) { | ||
| // since Orc includes NaN for upper/lower bounds of floating point columns, and we don't want this behavior, | ||
| // we have tracked metrics for such columns ourselves and thus do not need to rely on Orc's column statistics. | ||
| Preconditions.checkNotNull(fieldMetrics, | ||
| "[BUG] Float or double type columns should have metrics being tracked by Iceberg Orc writers"); | ||
| max = fieldMetrics.upperBound(); | ||
| if (fieldMetrics != null) { | ||
| // since Orc includes NaN for upper/lower bounds of floating point columns, and we don't want this behavior, | ||
| // we have tracked metrics for such columns ourselves and thus do not need to rely on Orc's column statistics. | ||
| max = fieldMetrics.upperBound(); | ||
| } else { | ||
| // imported files will not have metrics that were tracked by Iceberg, so fall back to the file's metrics. | ||
| max = replaceNaN(((DoubleColumnStatistics) columnStats).getMaximum(), Double.POSITIVE_INFINITY); | ||
| if (type.typeId() == Type.TypeID.FLOAT) { | ||
| max = ((Double) max).floatValue(); | ||
| } | ||
| } | ||
|
Contributor
Author
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 tested without this fix and encountered the error, so I'm sure that the test does in fact hit the problem. |
||
| } else if (columnStats instanceof StringColumnStatistics) { | ||
| max = ((StringColumnStatistics) columnStats).getMaximum(); | ||
| } else if (columnStats instanceof DecimalColumnStatistics) { | ||
|
|
@@ -262,6 +273,10 @@ private static Optional<ByteBuffer> fromOrcMax(Type type, ColumnStatistics colum | |
| return Optional.ofNullable(Conversions.toByteBuffer(type, truncateIfNeeded(Bound.UPPER, type, max, metricsMode))); | ||
| } | ||
|
|
||
| private static Object replaceNaN(double value, double replacement) { | ||
| return Double.isNaN(value) ? replacement : value; | ||
| } | ||
|
|
||
| private static Object truncateIfNeeded(Bound bound, Type type, Object value, MetricsMode metricsMode) { | ||
| // Out of the two types which could be truncated, string or binary, ORC only supports string bounds. | ||
| // Therefore, truncation will be applied if needed only on string type. | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.