kazuyukitanimura commented on a change in pull request #34611:
URL: https://github.com/apache/spark/pull/34611#discussion_r751886931
##########
File path:
sql/core/src/main/java/org/apache/spark/sql/execution/datasources/parquet/VectorizedPlainValuesReader.java
##########
@@ -53,20 +53,45 @@ public void skip() {
throw new UnsupportedOperationException();
}
+ private void updateCurrentByte() {
+ try {
+ currentByte = 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();
+ int totalByte = total / 8;
+ if (totalByte > 0) {
+ try {
+ in.skipFully(totalByte - 1L);
Review comment:
Right, the first line should have been
```
int totalByte = (bitOffset + total) / 8;
```
`Why -1?`: Because we read another byte in the very next line and update
`currentByte`.
E.g. skipping 9 values means `bitOffset = 0` and `total = 9`, then
```
int totalByte = (bitOffset + total) / 8; // = (0+9)/8 = 1
bitOffset = (bitOffset + total) & 7; // = (0+9)&7 = 1
...
in.skipFully(totalBytes - 1L); // in.skipFully(0)
if (bitOffset > 0) {
currentByte = in.read(); // making currentByte ready
}
```
`read 7 values and ... skip 11?`: For this example, `bitOffset = 7` is given
and running `skipBooleans(total = 11)` will be
```
int totalByte = (bitOffset + total) / 8; // = (7+11)/8 = 2
bitOffset = (bitOffset + total) & 7; // = (7+11)&7 = 2
...
in.skipFully(totalBytes - 1L); // in.skipFully(1)
if (bitOffset > 0) {
currentByte = in.read(); // making currentByte ready
}
...
```
--
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]