You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/11/16 23:12:48 UTC
[GitHub] [spark] sunchao commented on a change in pull request #34611: [SPARK-35867][SQL] Enable vectorized read for VectorizedPlainValuesReader.readBooleans
sunchao commented on a change in pull request #34611:
URL: https://github.com/apache/spark/pull/34611#discussion_r750731539
##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/WritableColumnVector.java
##########
@@ -179,6 +180,18 @@ public WritableColumnVector reserveDictionaryIds(int capacity) {
*/
protected abstract void reserveInternal(int capacity);
+ /**
+ * Each byte of the returned value (long) has one bit from `bits`. I.e. it is equivalent to
+ * byte[] a = {(byte)(bits >> 0 & 1), (byte)(bits >> 1 & 1),
+ * (byte)(bits >> 2 & 1), (byte)(bits >> 3 & 1),
+ * (byte)(bits >> 4 & 1), (byte)(bits >> 5 & 1),
+ * (byte)(bits >> 6 & 1), (byte)(bits >> 7 & 1)};
+ * return ByteBuffer.wrap(a).getLong();
+ */
+ protected final long toBitPerByte(int bits) {
+ return ((bits * 0x8040201008040201L) >>> 7) & 0x101010101010101L;
Review comment:
hm why we need a multiplication here? have you tried a loop with simple shift and mask - wonder how much different it will be.
##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/WritableColumnVector.java
##########
@@ -201,6 +214,15 @@ public WritableColumnVector reserveDictionaryIds(int capacity) {
*/
public abstract void putBooleans(int rowId, int count, boolean value);
+ /**
+ * Sets bits from [src[srcIndex], src[srcIndex + count]) to [rowId, rowId + count)
+ * src must be positive and contain 8 bits of bitmask in the lowest byte.
+ */
+ public void putBooleans(int rowId, int count, int src, int srcIndex) {
+ putBytes(rowId, count, ByteBuffer.allocate(8).putLong(toBitPerByte(src)).array(), srcIndex);
+ }
+ public void putBooleans(int rowId, int src) {putBooleans(rowId, 8, src, 0);}
Review comment:
nit: space
##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/WritableColumnVector.java
##########
@@ -201,6 +214,15 @@ public WritableColumnVector reserveDictionaryIds(int capacity) {
*/
public abstract void putBooleans(int rowId, int count, boolean value);
+ /**
+ * Sets bits from [src[srcIndex], src[srcIndex + count]) to [rowId, rowId + count)
+ * src must be positive and contain 8 bits of bitmask in the lowest byte.
+ */
+ public void putBooleans(int rowId, int count, int src, int srcIndex) {
Review comment:
why this takes a `int` for `src`, can we use `byte`?
##########
File path: sql/core/src/test/scala/org/apache/spark/sql/execution/benchmark/DataSourceReadBenchmark.scala
##########
@@ -541,6 +548,9 @@ object DataSourceReadBenchmark extends SqlBasedBenchmark {
}
override def runBenchmarkSuite(mainArgs: Array[String]): Unit = {
+ runBenchmark("SQL Single Boolean Column Scan") {
+ numericScanBenchmark(1024 * 1024 * 15, BooleanType)
Review comment:
I wonder if we can just add `BooleanType` to the benchmark below, together with other types.
##########
File path: sql/core/src/main/java/org/apache/spark/sql/execution/vectorized/WritableColumnVector.java
##########
@@ -201,6 +214,15 @@ public WritableColumnVector reserveDictionaryIds(int capacity) {
*/
public abstract void putBooleans(int rowId, int count, boolean value);
+ /**
+ * Sets bits from [src[srcIndex], src[srcIndex + count]) to [rowId, rowId + count)
+ * src must be positive and contain 8 bits of bitmask in the lowest byte.
+ */
+ public void putBooleans(int rowId, int count, int src, int srcIndex) {
+ putBytes(rowId, count, ByteBuffer.allocate(8).putLong(toBitPerByte(src)).array(), srcIndex);
Review comment:
can we reuse the bytes here instead of allocating each time?
##########
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;
Review comment:
can we just do `bitOffset = 0` here?
--
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: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org