Skip to content

Commit ae0e447

Browse files
committed
add finally to avoid resource leak
1 parent e678b9f commit ae0e447

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,15 @@ case class InsertIntoParquetTable(
298298
val committer = format.getOutputCommitter(hadoopContext)
299299
committer.setupTask(hadoopContext)
300300
val writer = format.getRecordWriter(hadoopContext)
301-
while (iter.hasNext) {
302-
val row = iter.next()
303-
writer.write(null, row)
301+
try {
302+
while (iter.hasNext) {
303+
val row = iter.next()
304+
writer.write(null, row)
305+
}
306+
}
307+
finally {
308+
writer.close(hadoopContext)
304309
}
305-
writer.close(hadoopContext)
306310
committer.commitTask(hadoopContext)
307311
return 1
308312
}

0 commit comments

Comments
 (0)