zsxwing commented on a change in pull request #24154: [SPARK-27210][SS] Cleanup 
incomplete output files in ManifestFileCommitProtocol if task is aborted
URL: https://github.com/apache/spark/pull/24154#discussion_r267558635
 
 

 ##########
 File path: 
sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSinkSuite.scala
 ##########
 @@ -478,4 +481,48 @@ class FileStreamSinkSuite extends StreamTest {
       checkDatasetUnorderly(outputDf, 1, 2, 3)
     }
   }
+
+  test("cleanup incomplete output for aborted task") {
+    withSQLConf(("spark.sql.streaming.commitProtocolClass",
+      classOf[TaskFailToCommitManifestFileCommitProtocol].getCanonicalName)) {
+      withTempDir { tempDir =>
+        val checkpointDir = new File(tempDir, "chk")
+        val outputDir = new File(tempDir, "output")
+        val inputData = MemoryStream[Int]
+        inputData.addData(1, 2, 3)
+        val q = inputData.toDF()
+          .writeStream
+          .option("checkpointLocation", checkpointDir.getCanonicalPath)
+          .format("parquet")
+          .start(outputDir.getCanonicalPath)
+
+        intercept[StreamingQueryException] {
+          try {
+            q.processAllAvailable()
+          } finally {
+            q.stop()
+          }
+        }
+
+        import scala.collection.JavaConverters._
+        val outputFiles = Files.walk(outputDir.toPath).iterator().asScala
+          .filter(p => Files.isRegularFile(p) && p.endsWith(".parquet"))
+        assert(outputFiles.length === 0, "Incomplete files should be cleaned 
up.")
 
 Review comment:
   nit: `outputFiles.toList.isEmpty` is better than `Iterator` as the latter 
won't write the content into the error message.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to