-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-31606][SQL] Reduce the perf regression of vectorized parquet reader caused by datetime rebase #28406
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
[SPARK-31606][SQL] Reduce the perf regression of vectorized parquet reader caused by datetime rebase #28406
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import org.apache.parquet.io.ParquetDecodingException; | ||
| import org.apache.parquet.io.api.Binary; | ||
|
|
||
| import org.apache.spark.sql.catalyst.util.RebaseDateTime; | ||
| import org.apache.spark.sql.execution.vectorized.WritableColumnVector; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -203,6 +204,43 @@ public void readIntegers( | |
| } | ||
| } | ||
|
|
||
| // A fork of `readIntegers`, which rebases the date int value (days) before filling | ||
| // the Spark column vector. | ||
| public void readIntegersWithRebase( | ||
| int total, | ||
| WritableColumnVector c, | ||
| int rowId, | ||
| int level, | ||
| VectorizedValuesReader data) throws IOException { | ||
| int left = total; | ||
| while (left > 0) { | ||
| if (this.currentCount == 0) this.readNextGroup(); | ||
| int n = Math.min(left, this.currentCount); | ||
| switch (mode) { | ||
| case RLE: | ||
| if (currentValue == level) { | ||
| data.readIntegersWithRebase(n, c, rowId); | ||
| } else { | ||
| c.putNulls(rowId, n); | ||
| } | ||
| break; | ||
| case PACKED: | ||
| for (int i = 0; i < n; ++i) { | ||
| if (currentBuffer[currentBufferIdx++] == level) { | ||
| c.putInt(rowId + i, | ||
| RebaseDateTime.rebaseJulianToGregorianDays(data.readInteger())); | ||
| } else { | ||
| c.putNull(rowId + i); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| rowId += n; | ||
| left -= n; | ||
| currentCount -= n; | ||
| } | ||
| } | ||
|
|
||
| // TODO: can this code duplication be removed without a perf penalty? | ||
| public void readBooleans( | ||
| int total, | ||
|
|
@@ -342,6 +380,43 @@ public void readLongs( | |
| } | ||
| } | ||
|
|
||
| // A fork of `readLongs`, which rebases the timestamp long value (microseconds) before filling | ||
| // the Spark column vector. | ||
| public void readLongsWithRebase( | ||
| int total, | ||
| WritableColumnVector c, | ||
| int rowId, | ||
| int level, | ||
| VectorizedValuesReader data) throws IOException { | ||
| int left = total; | ||
| while (left > 0) { | ||
| if (this.currentCount == 0) this.readNextGroup(); | ||
| int n = Math.min(left, this.currentCount); | ||
| switch (mode) { | ||
| case RLE: | ||
| if (currentValue == level) { | ||
| data.readLongsWithRebase(n, c, rowId); | ||
| } else { | ||
| c.putNulls(rowId, n); | ||
| } | ||
| break; | ||
| case PACKED: | ||
|
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. Is it impossible to optimize the case too?
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 didn't optimize this case because the no-rebase code path looks not very fast. It has a
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. The general idea is to add an extra loop to check if we need to rebase or not, and it's only worthwhile if the no-rebase code path is much faster than the rebase code path. |
||
| for (int i = 0; i < n; ++i) { | ||
| if (currentBuffer[currentBufferIdx++] == level) { | ||
| c.putLong(rowId + i, | ||
| RebaseDateTime.rebaseJulianToGregorianMicros(data.readLong())); | ||
| } else { | ||
| c.putNull(rowId + i); | ||
| } | ||
| } | ||
| break; | ||
| } | ||
| rowId += n; | ||
| left -= n; | ||
| currentCount -= n; | ||
| } | ||
| } | ||
|
|
||
| public void readFloats( | ||
| int total, | ||
| WritableColumnVector c, | ||
|
|
@@ -508,6 +583,11 @@ public void readIntegers(int total, WritableColumnVector c, int rowId) { | |
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void readIntegersWithRebase(int total, WritableColumnVector c, int rowId) { | ||
| throw new UnsupportedOperationException("only readInts is valid."); | ||
| } | ||
|
|
||
| @Override | ||
| public byte readByte() { | ||
| throw new UnsupportedOperationException("only readInts is valid."); | ||
|
|
@@ -523,6 +603,11 @@ public void readLongs(int total, WritableColumnVector c, int rowId) { | |
| throw new UnsupportedOperationException("only readInts is valid."); | ||
| } | ||
|
|
||
| @Override | ||
| public void readLongsWithRebase(int total, WritableColumnVector c, int rowId) { | ||
| throw new UnsupportedOperationException("only readInts is valid."); | ||
| } | ||
|
|
||
| @Override | ||
| public void readBinary(int total, WritableColumnVector c, int rowId) { | ||
| throw new UnsupportedOperationException("only readInts is valid."); | ||
|
|
||
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 byte code of the loop is:
We could avoid mul like
Would it be faster?
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 tried it and the perf has no difference.