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

[NE-400] fix memory leakage in native columnartorow #1044

Merged
merged 1 commit into from
Jul 29, 2022
Merged
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 @@ -29,6 +29,7 @@ import org.apache.spark.sql.execution.datasources.v2.arrow.SparkMemoryUtils
import org.apache.spark.sql.execution.metric.{SQLMetric, SQLMetrics}
import org.apache.spark.sql.execution.{CodegenSupport, ColumnarToRowTransition, SparkPlan}
import org.apache.spark.sql.types._
import org.apache.spark.TaskContext

import scala.collection.JavaConverters._
import scala.collection.mutable.ListBuffer
Expand Down Expand Up @@ -146,13 +147,21 @@ case class ArrowColumnarToRowExec(child: SparkPlan) extends ColumnarToRowTransit
var rowId = 0
val row = new UnsafeRow(batch.numCols())
var closed = false

TaskContext.get().addTaskCompletionListener[Unit](_ => {
if (!closed) {
jniWrapper.nativeClose(info.instanceID)
closed = true
}
})

override def hasNext: Boolean = {
val result = rowId < batch.numRows()
if (!result && !closed) {
jniWrapper.nativeClose(info.instanceID)
closed = true
}
return result
result
}

override def next: UnsafeRow = {
Expand Down