kazuyukitanimura commented on a change in pull request #34611:
URL: https://github.com/apache/spark/pull/34611#discussion_r754843844
##########
File path:
sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedPlainValuesReader.java
##########
@@ -53,19 +53,50 @@ public void skip() {
throw new UnsupportedOperationException();
}
+ private void updateCurrentByte() {
+ try {
+ currentByte = (byte) in.read();
+ } catch (IOException e) {
+ throw new ParquetDecodingException("Failed to read a byte", e);
+ }
+ }
+
@Override
public final void readBooleans(int total, WritableColumnVector c, int rowId)
{
- // TODO: properly vectorize this
- for (int i = 0; i < total; i++) {
- c.putBoolean(rowId + i, readBoolean());
+ int i = 0;
+ if (bitOffset > 0) {
+ i = Math.min(8 - bitOffset, total);
+ c.putBooleans(rowId, i, currentByte, bitOffset);
+ bitOffset = (bitOffset + i) & 7;
+ }
+ for (; i + 7 < total; i += 8) {
+ updateCurrentByte();
+ c.putBooleans(rowId + i, currentByte);
+ }
+ if (i < total) {
+ updateCurrentByte();
+ bitOffset = total - i;
+ c.putBooleans(rowId + i, bitOffset, currentByte, 0);
}
}
@Override
public final void skipBooleans(int total) {
- // TODO: properly vectorize this
- for (int i = 0; i < total; i++) {
- readBoolean();
+ // Using >>3 instead of /8 below. The difference is important when
(total-(8-bitOffset))<0.
+ // E.g. (-1)>>3=(-1) vs. (-1)/8=0. The latter incorrectly enters the
if(numBytesToSkip>=0){.
Review comment:
Let's say `total=8`, `bitOffset=1`, then there are `(8-bitOffset)=7`
bits to skip in the `currentByte`. Now there is still 1 more bit to skip as
`total=8`. So `updateCurrentByte()` needs to be called to update the
`currentByte` and `bitOffset` will be again `1`. In the future, the rest of
the 7bits may be read from the updated `currentByte`. For that reason, we need
to go into the if statement when `numBytesToSkip = (8 - (8 - 1)) >> 3 = 1>>3 =
0`.
The following is a few-lines longer but equivalent condition.
```
if (numBytesToSkip > 0) {
try {
in.skipFully(numBytesToSkip);
} catch (IOException e) {...}
}
if (numBytesToSkip >= 0 && bitOffset > 0) {
updateCurrentByte();
}
```
The scenario is tested at
https://github.com/apache/spark/pull/34611/files#diff-b84cbbb2eadfa9d267b9ab8be2e6be579f28c1813623785c9e667a864f7960e1R194
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]