Skip to content

Commit

Permalink
Correctly close iterator when reading large log files in Delta Stream…
Browse files Browse the repository at this point in the history
…ing Source

GitOrigin-RevId: a31e0529bf169d4a1f1e85b9c14982a83a899767
  • Loading branch information
allisonport-db authored and scottsand-db committed Jan 26, 2022
1 parent 1dd2ea0 commit 8ae11af
Showing 1 changed file with 9 additions and 5 deletions.
Expand Up @@ -284,12 +284,16 @@ case class DeltaSource(
initialState.iterator()
}

protected def iteratorLast[T](iter: Iterator[T]): Option[T] = {
var last: Option[T] = None
while (iter.hasNext) {
last = Some(iter.next())
protected def iteratorLast[T](iter: ClosableIterator[T]): Option[T] = {
try {
var last: Option[T] = None
while (iter.hasNext) {
last = Some(iter.next())
}
last
} finally {
iter.close()
}
last
}

private def getStartingOffset(
Expand Down

0 comments on commit 8ae11af

Please sign in to comment.