-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
PARQUET-2365 : Fixes NPE when rewriting column without column index #1173
Conversation
Hi @wgtmac, please help to review this when you are free. Thanks a lot. |
@@ -543,6 +546,11 @@ public static ColumnIndex build( | |||
* the statistics to be added | |||
*/ | |||
public void add(Statistics<?> stats) { | |||
if (stats.isEmpty()) { |
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.
It should be invalid if the stats are empty. Previously we set it as a null page. @gszadovszky please correct me if I am wrong.
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.
I am not sure how column index writing worked for the "rewriter". This rewriting thing is newer than the column index. In the normal writing scenario stats
cannot be empty since we are just creating these objects during the write path.
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.
This is especially used when the ColumnIndex
is null during rewriting. And we pass empty statistics to the ColumnIndexBuilder
to avoid NPE.
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.
Let me try to understand what happens here. convertStatistics
is used to recover page statistics from ColumnIndex or original page header if the ColumnIndex is unavailable. The problem emerges when ColumnIndex is unavailable. Am I correct? If true, then why do we need those changes in the ColumnIndexBuilder?
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.
The problem happens when both the ColumnIndex
and the page header Statistics
are null. Because we get null
returned from the convertStatistics
. However, the ParquetFileWriter.writeDataPage
needs the page statistics. So here we pass invalid page statistics to avoid the NPE and overwrite the column statistics in the end. Otherwise, we need to add some methods that don't need page statistics.
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.
From what you have said, it seems that the problem comes from the input file which has valid aggregate statistics for the column chunk but does not write page statistics in the page header. Should we just fix the NPE in the page header and leave other parts as is?
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.
Should we just fix the NPE in the page header and leave other parts as is?
Updated the implementation.
* @param totalStatistics the column total statistics | ||
* @throws IOException if there is an error while writing | ||
*/ | ||
public void endColumn(Statistics<?> totalStatistics) throws IOException { |
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.
Exposing this to public is not a good idea. Other good suggestions are welcome.
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.
Since this is used only for invalid stats, is it better to add a void invalidateStatistics()
which simply include line 988 and 990? Then you just need to call invalidateStatistics() and endColumn() in this case.
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.
This is used to set the column aggregated statistics. Do you mean to modify the public void endColumn(Statistics<?> totalStatistics)
to public void invalidateStatistics(Statistics<?> totalStatistics)
?
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.
Replaced with invalidateStatistics
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/ParquetRewriter.java
Outdated
Show resolved
Hide resolved
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
Outdated
Show resolved
Hide resolved
@@ -543,6 +546,11 @@ public static ColumnIndex build( | |||
* the statistics to be added | |||
*/ | |||
public void add(Statistics<?> stats) { | |||
if (stats.isEmpty()) { |
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.
Let me try to understand what happens here. convertStatistics
is used to recover page statistics from ColumnIndex or original page header if the ColumnIndex is unavailable. The problem emerges when ColumnIndex is unavailable. Am I correct? If true, then why do we need those changes in the ColumnIndexBuilder?
...-column/src/main/java/org/apache/parquet/internal/column/columnindex/ColumnIndexBuilder.java
Outdated
Show resolved
Hide resolved
@@ -543,6 +546,11 @@ public static ColumnIndex build( | |||
* the statistics to be added | |||
*/ | |||
public void add(Statistics<?> stats) { | |||
if (stats.isEmpty()) { |
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.
From what you have said, it seems that the problem comes from the input file which has valid aggregate statistics for the column chunk but does not write page statistics in the page header. Should we just fix the NPE in the page header and leave other parts as is?
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
Show resolved
Hide resolved
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
Outdated
Show resolved
Hide resolved
94b0cd1
to
7019e74
Compare
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
Show resolved
Hide resolved
* @param totalStatistics the column total statistics | ||
* @throws IOException if there is an error while writing | ||
*/ | ||
public void endColumn(Statistics<?> totalStatistics) throws IOException { |
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.
Since this is used only for invalid stats, is it better to add a void invalidateStatistics()
which simply include line 988 and 990? Then you just need to call invalidateStatistics() and endColumn() in this case.
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/ParquetRewriter.java
Outdated
Show resolved
Hide resolved
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/ParquetRewriter.java
Outdated
Show resolved
Hide resolved
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.
Thanks. LGTM
It seems that a rebase is required to make CIs happy. |
…/ParquetRewriter.java Co-authored-by: Gang Wu <[email protected]>
adfd647
to
8da6804
Compare
Just rebased |
Thanks @wgtmac @gszadovszky |
Hi, @wgtmac @gszadovszky should we port this to 1.13.x branch? And is there any plan for a new release? |
IMO, there isn't any plan for 1.13.2 release. But you may port it to 1.13.x branch just in case. |
OK, I will port it. |
Make sure you have checked all steps below.
Jira
Tests
Commits
Documentation
The ColumnIndex could be null in some scenes, for example, the float/double column contains NaN or the size has exceeded the expected value. And the page header statistics are not written anymore after we supported ColumnIndex. So we will get NPE when rewriting the column without ColumnIndex due to we will get NULL page statistics when converted from the ColumnIndex(NULL) or page header statistics(NULL). Such as the following: