Github user lw-lin commented on a diff in the pull request: https://github.com/apache/spark/pull/16987#discussion_r103104036 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala --- @@ -662,6 +663,101 @@ class FileStreamSourceSuite extends FileStreamSourceTest { } } + testWithUninterruptibleThread("read data from outputs of another streaming query") { + withSQLConf(SQLConf.FILE_SINK_LOG_COMPACT_INTERVAL.key -> "3") { + withTempDirs { case (dir, tmp) => + val sinkLogDir = new File(dir, FileStreamSink.metadataDir).getCanonicalPath + val sinkLog = new FileStreamSinkLog(FileStreamSinkLog.VERSION, spark, sinkLogDir) + + val fileStream = createFileStream("text", dir.getCanonicalPath) + val filtered = fileStream.filter($"value" contains "keep") + + def addIntoSinkLog(batch: Int, fileName: String): Boolean = { + val unqualifiedDirPath = new Path(new File(dir, fileName).getCanonicalPath) + val fs = unqualifiedDirPath.getFileSystem(sparkContext.hadoopConfiguration) + val sinkFileStatus = SinkFileStatus(fs.getFileStatus(unqualifiedDirPath)) + sinkLog.add(batch, Array(sinkFileStatus)) + } + + testStream(filtered)( + // Create new dir and write to it, should read + AddTextFileData("drop1\nkeep2", dir, tmp, Some("file_1")), + Assert { addIntoSinkLog(0, "file_1") }, + CheckAnswer("keep2"), + + // Create "file_2" but DO NOT add it to the log intentionally + AddTextFileData("should_not_keep!!!", dir, tmp, Some("file_2")), + Assert { new File(dir, "file_2").exists() }, + AddTextFileData("keep3", dir, tmp, Some("file_3")), + Assert { addIntoSinkLog(1, "file_3") }, + // Should NOT read "file_2"; should read "file_3" + CheckAnswer("keep2", "keep3"), + + // Check that things work well when the sink log gets compacted + AddTextFileData("keep4", dir, tmp, Some("file_4")), + Assert { addIntoSinkLog(2, "file_4") }, + Assert { + // compact interval is 3, so file "2.compact" should exist + new File(sinkLogDir, "2" + CompactibleFileStreamLog.COMPACT_FILE_SUFFIX).exists() + }, + CheckAnswer("keep2", "keep3", "keep4"), + + AddTextFileData("keep5", dir, tmp, Some("file_5")), + Assert { addIntoSinkLog(3, "file_5") }, + CheckAnswer("keep2", "keep3", "keep4", "keep5") + ) + } + } + } + + testWithUninterruptibleThread("read partitioned data from outputs of another streaming query") { --- End diff -- done
--- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org