Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
viirya committed Dec 17, 2024
1 parent 6e35d24 commit 0418e1d
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions spark/src/main/scala/org/apache/comet/CometExecIterator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class CometExecIterator(
}

private var nextBatch: Option[ColumnarBatch] = None
private var prevBatch: ColumnarBatch = null
private var currentBatch: ColumnarBatch = null
private var closed: Boolean = false

Expand All @@ -95,6 +96,14 @@ class CometExecIterator(
return true
}

// Close previous batch if any.
// This is to guarantee safety at the native side before we overwrite the buffer memory
// shared across batches in the native side.
if (prevBatch != null) {
prevBatch.close()
prevBatch = null
}

nextBatch = getNextBatch()

if (nextBatch.isEmpty) {
Expand All @@ -117,6 +126,7 @@ class CometExecIterator(
}

currentBatch = nextBatch.get
prevBatch = currentBatch
nextBatch = None
currentBatch
}
Expand Down

0 comments on commit 0418e1d

Please sign in to comment.