aboutsummaryrefslogtreecommitdiff
path: root/sql/core
diff options
context:
space:
mode:
authorbaishuo <vc_java@hotmail.com>2014-12-02 12:12:03 -0800
committerMichael Armbrust <michael@databricks.com>2014-12-02 12:12:03 -0800
commit69b6fed206565ecb0173d3757bcb5110422887c3 (patch)
tree273a706100b41a0ef56dbce4d3723b88a753ae93 /sql/core
parente75e04f980281389b881df76f59ba1adc6338629 (diff)
downloadspark-69b6fed206565ecb0173d3757bcb5110422887c3.tar.gz
spark-69b6fed206565ecb0173d3757bcb5110422887c3.tar.bz2
spark-69b6fed206565ecb0173d3757bcb5110422887c3.zip
[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
Diffstat (limited to 'sql/core')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala11
1 files changed, 7 insertions, 4 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala b/sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala
index 0e36852ddd..232ef90b01 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/parquet/ParquetTableOperations.scala
@@ -302,11 +302,14 @@ case class InsertIntoParquetTable(
val committer = format.getOutputCommitter(hadoopContext)
committer.setupTask(hadoopContext)
val writer = format.getRecordWriter(hadoopContext)
- while (iter.hasNext) {
- val row = iter.next()
- writer.write(null, row)
+ try {
+ while (iter.hasNext) {
+ val row = iter.next()
+ writer.write(null, row)
+ }
+ } finally {
+ writer.close(hadoopContext)
}
- writer.close(hadoopContext)
committer.commitTask(hadoopContext)
1
}