Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[NSE-746]Fix memory allocation in row to columnar #834

Merged
merged 3 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ case class ArrowRowToColumnarExec(child: SparkPlan) extends UnaryExecNode {
val unsafeRow = row.asInstanceOf[UnsafeRow]
val sizeInBytes = unsafeRow.getSizeInBytes
if ((offset + sizeInBytes) > arrowBuf.capacity()) {
val tmpBuf = allocator.buffer(((offset + sizeInBytes) * 1.5).toLong)
tmpBuf.setBytes(0, arrowBuf, 0, offset)
arrowBuf.close()
arrowBuf = allocator.buffer((arrowBuf.capacity() * 1.2).toLong)
arrowBuf = tmpBuf
}
Platform.copyMemory(unsafeRow.getBaseObject, unsafeRow.getBaseOffset,
null, arrowBuf.memoryAddress() + offset, sizeInBytes)
Expand All @@ -192,7 +194,7 @@ case class ArrowRowToColumnarExec(child: SparkPlan) extends UnaryExecNode {
processTime.set(NANOSECONDS.toMillis(elapse))
last_cb
} else {
logInfo("the buffer allocated failed and will fall back to non arrow optimization")
logInfo("not unsaferow, fallback to java based r2c")
val vectors: Seq[WritableColumnVector] =
ArrowWritableColumnVector.allocateColumns(numRows, schema)
var rowCount = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class SortSuite extends SparkPlanTest with SharedSparkSession {
override protected def sparkConf: SparkConf = {
val conf = super.sparkConf
conf.set("spark.memory.offHeap.size", String.valueOf("5000m"))
.set("spark.sql.inMemoryColumnarStorage.batchSize", "100")
}

test("basic sorting using ExternalSort") {
Expand Down