Skip to content

Commit aa3d369

Browse files
baishuomarmbrus
authored andcommitted
[SPARK-4663][sql]add finally to avoid resource leak
Author: baishuo <vc_java@hotmail.com> Closes #3526 from baishuo/master-trycatch and squashes the following commits: d446e14 [baishuo] correct the code style b36bf96 [baishuo] correct the code style ae0e447 [baishuo] add finally to avoid resource leak (cherry picked from commit 69b6fed) Signed-off-by: Michael Armbrust <michael@databricks.com>
1 parent 1850d90 commit aa3d369

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,14 @@ case class InsertIntoParquetTable(
302302
val committer = format.getOutputCommitter(hadoopContext)
303303
committer.setupTask(hadoopContext)
304304
val writer = format.getRecordWriter(hadoopContext)
305-
while (iter.hasNext) {
306-
val row = iter.next()
307-
writer.write(null, row)
305+
try {
306+
while (iter.hasNext) {
307+
val row = iter.next()
308+
writer.write(null, row)
309+
}
310+
} finally {
311+
writer.close(hadoopContext)
308312
}
309-
writer.close(hadoopContext)
310313
committer.commitTask(hadoopContext)
311314
1
312315
}

0 commit comments

Comments
 (0)