mengw15 commented on code in PR #5149:
URL: https://github.com/apache/texera/pull/5149#discussion_r3290650123


##########
common/workflow-core/src/main/scala/org/apache/texera/amber/util/IcebergUtil.scala:
##########
@@ -428,7 +434,32 @@ object IcebergUtil {
         .project(schema)
         .createReaderFunc(readerFunc)
         .build()
-    closeableIterable.iterator().asScala
+    new CloseableScalaIterator(closeableIterable)
   }
 
 }
+
+/**
+  * A Scala `Iterator` that also owns the lifecycle of an Iceberg
+  * `CloseableIterable`. Closing this iterator (or letting `Using.resource`
+  * close it) releases the underlying CloseableIterable, which in turn closes
+  * the Parquet reader / S3InputStream / AWS HTTP-pool slot that the iterable
+  * acquired.
+  */
+class CloseableScalaIterator[T](source: CloseableIterable[T])

Review Comment:
   Done. The root issue was that `.asScala` strips the close handle (Scala's 
`Iterator` has no `close`), so callers couldn't release the parent 
`CloseableIterable`. The wrapper class was one way to carry the close 
alongside; the simpler approach — now in the PR — is to NOT `.asScala` at the 
util level. `readDataFileAsIterator` returns Iceberg's 
`CloseableIterator[Record]` raw; `IcebergDocument` holds it as an 
`AutoCloseable` and calls `.asScala` only when it needs Scala iterator 
semantics (for `.drop`).
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to