Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouxxyy committed Dec 29, 2024
1 parent 8ab1247 commit 7379bb4
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache

import org.apache.hudi.common.util.collection.ClosableIterator
import org.apache.spark.sql.{DataFrame, DataFrameReader, DataFrameWriter}

package object hudi {
Expand All @@ -35,4 +36,19 @@ package object hudi {
def avro: String => DataFrame = reader.format("org.apache.hudi").load
}

/**
* An implicit class that cast java [[ClosableIterator]] to a scala [[Iterator]].
*/
implicit class ScalaClosableIterator[T](closableIterator: ClosableIterator[T]) extends Iterator[T] {

override def hasNext: Boolean = closableIterator.hasNext

override def next(): T = {
val _next = closableIterator.next()
if (!hasNext) {
closableIterator.close()
}
_next
}
}
}

0 comments on commit 7379bb4

Please sign in to comment.