vanzin commented on a change in pull request #22952: [SPARK-20568][SS] Provide
option to clean up completed files in streaming query
URL: https://github.com/apache/spark/pull/22952#discussion_r338327182
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala
##########
@@ -1596,6 +1615,282 @@ class FileStreamSourceSuite extends
FileStreamSourceTest {
}
}
}
+
+ test("remove completed files when remove option is enabled") {
+ def assertFileIsRemoved(files: Array[String], fileName: String): Unit = {
+ assert(!files.exists(_.startsWith(fileName)))
+ }
+
+ def assertFileIsNotRemoved(files: Array[String], fileName: String): Unit =
{
+ assert(files.exists(_.startsWith(fileName)))
+ }
+
+ withTempDirs { case (src, tmp) =>
+ withSQLConf(
+ SQLConf.FILE_SOURCE_LOG_COMPACT_INTERVAL.key -> "2",
+ // Force deleting the old logs
+ SQLConf.FILE_SOURCE_LOG_CLEANUP_DELAY.key -> "1"
+ ) {
+ val option = Map("latestFirst" -> "false", "maxFilesPerTrigger" -> "1",
+ "cleanSource" -> "delete")
+
+ val fileStream = createFileStream("text", src.getCanonicalPath,
options = option)
+ val filtered = fileStream.filter($"value" contains "keep")
+
+ testStream(filtered)(
+ AddTextFileData("keep1", src, tmp, tmpFilePrefix = "keep1"),
+ CheckAnswer("keep1"),
+ AssertOnQuery("input file removed") { _: StreamExecution =>
+ // it doesn't rename any file yet
+ assertFileIsNotRemoved(src.list(), "keep1")
+ true
+ },
+ AddTextFileData("keep2", src, tmp, tmpFilePrefix = "ke ep2 %"),
+ CheckAnswer("keep1", "keep2"),
+ AssertOnQuery("input file removed") { _: StreamExecution =>
+ val files = src.list()
+
+ // it renames input file for first batch, but not for second batch
yet
+ assertFileIsRemoved(files, "keep1")
+ assertFileIsNotRemoved(files, "ke ep2 %")
+
+ true
+ },
+ AddTextFileData("keep3", src, tmp, tmpFilePrefix = "keep3"),
+ CheckAnswer("keep1", "keep2", "keep3"),
+ AssertOnQuery("input file renamed") { _: StreamExecution =>
+ val files = src.list()
+
+ // it renames input file for second batch, but not third batch yet
+ assertFileIsRemoved(files, "ke ep2 %")
+ assertFileIsNotRemoved(files, "keep3")
+
+ true
+ }
+ )
+ }
+ }
+ }
+
+ test("move completed files to archive directory when archive option is
enabled") {
+
Review comment:
remove empty line
----------------------------------------------------------------
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]