Repository: spark
Updated Branches:
  refs/heads/branch-1.5 4de833e9e -> 5452e93f0


[SQL][minor] Simplify UnsafeRow.calculateBitSetWidthInBytes.

Author: Reynold Xin <r...@databricks.com>

Closes #7897 from rxin/calculateBitSetWidthInBytes and squashes the following 
commits:

2e73b3a [Reynold Xin] [SQL][minor] Simplify 
UnsafeRow.calculateBitSetWidthInBytes.

(cherry picked from commit 7a9d09f0bb472a1671d3457e1f7108f4c2eb4121)
Signed-off-by: Reynold Xin <r...@databricks.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/5452e93f
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/5452e93f
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/5452e93f

Branch: refs/heads/branch-1.5
Commit: 5452e93f03bc308282cb8f189f65bb1b258d8813
Parents: 4de833e
Author: Reynold Xin <r...@databricks.com>
Authored: Mon Aug 3 11:22:02 2015 -0700
Committer: Reynold Xin <r...@databricks.com>
Committed: Mon Aug 3 11:22:10 2015 -0700

----------------------------------------------------------------------
 .../apache/spark/sql/catalyst/expressions/UnsafeRow.java  |  2 +-
 .../test/scala/org/apache/spark/sql/UnsafeRowSuite.scala  | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/5452e93f/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
----------------------------------------------------------------------
diff --git 
a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
 
b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
index f4230cf..e6750fc 100644
--- 
a/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
+++ 
b/sql/catalyst/src/main/java/org/apache/spark/sql/catalyst/expressions/UnsafeRow.java
@@ -59,7 +59,7 @@ public final class UnsafeRow extends MutableRow {
   
//////////////////////////////////////////////////////////////////////////////
 
   public static int calculateBitSetWidthInBytes(int numFields) {
-    return ((numFields / 64) + (numFields % 64 == 0 ? 0 : 1)) * 8;
+    return ((numFields + 63)/ 64) * 8;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/spark/blob/5452e93f/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala 
b/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala
index c5faaa6..89bad1b 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/UnsafeRowSuite.scala
@@ -28,6 +28,16 @@ import org.apache.spark.unsafe.memory.MemoryAllocator
 import org.apache.spark.unsafe.types.UTF8String
 
 class UnsafeRowSuite extends SparkFunSuite {
+
+  test("bitset width calculation") {
+    assert(UnsafeRow.calculateBitSetWidthInBytes(0) === 0)
+    assert(UnsafeRow.calculateBitSetWidthInBytes(1) === 8)
+    assert(UnsafeRow.calculateBitSetWidthInBytes(32) === 8)
+    assert(UnsafeRow.calculateBitSetWidthInBytes(64) === 8)
+    assert(UnsafeRow.calculateBitSetWidthInBytes(65) === 16)
+    assert(UnsafeRow.calculateBitSetWidthInBytes(128) === 16)
+  }
+
   test("writeToStream") {
     val row = InternalRow.apply(UTF8String.fromString("hello"), 
UTF8String.fromString("world"), 123)
     val arrayBackedUnsafeRow: UnsafeRow =


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to