Skip to content

Commit f3dcbfe

Browse files
committed
More mod replacement
1 parent 854201a commit f3dcbfe

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/UnsafeRowConverter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ private class StringUnsafeColumnWriter private() extends UnsafeColumnWriter[UTF8
8787
numBytes
8888
)
8989
row.setLong(columnNumber, appendCursor)
90-
8 + ((numBytes / 8) + (if (numBytes % 8 == 0) 0 else 1)) * 8
90+
8 + ByteArrayMethods.roundNumberOfBytesToNearestWord(numBytes)
9191
}
9292
}
9393
private object StringUnsafeColumnWriter extends StringUnsafeColumnWriter

unsafe/src/test/java/org/apache/spark/unsafe/string/TestUTF8String.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,24 @@
1717

1818
package org.apache.spark.unsafe.string;
1919

20+
import java.io.UnsupportedEncodingException;
21+
import java.lang.String;
22+
2023
import org.junit.Assert;
2124
import org.junit.Test;
2225

2326
import org.apache.spark.unsafe.memory.MemoryLocation;
2427
import org.apache.spark.unsafe.memory.MemoryBlock;
25-
import java.lang.String;
28+
import org.apache.spark.unsafe.array.ByteArrayMethods;
2629

2730
public class TestUTF8String {
2831

2932
@Test
30-
public void toStringTest() {
33+
public void toStringTest() throws UnsupportedEncodingException {
3134
final String javaStr = "Hello, World!";
3235
final byte[] javaStrBytes = javaStr.getBytes();
33-
final int paddedSizeInWords = javaStrBytes.length / 8 + (javaStrBytes.length % 8 == 0 ? 0 : 1);
36+
final int paddedSizeInWords =
37+
ByteArrayMethods.roundNumberOfBytesToNearestWord(javaStrBytes.length);
3438
final MemoryLocation memory = MemoryBlock.fromLongArray(new long[paddedSizeInWords]);
3539
final int bytesWritten = UTF8StringMethods.createFromJavaString(
3640
memory.getBaseObject(),

0 commit comments

Comments
 (0)