Github user lw-lin commented on a diff in the pull request: https://github.com/apache/spark/pull/16987#discussion_r103603705 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala --- @@ -662,6 +665,154 @@ class FileStreamSourceSuite extends FileStreamSourceTest { } } + test("read data from outputs of another streaming query") { + withSQLConf(SQLConf.FILE_SINK_LOG_COMPACT_INTERVAL.key -> "3") { + withTempDirs { case (dir, tmp) => + // q1 is a streaming query that reads from memory and writes to text files + val q1_source = MemoryStream[String] + val q1_checkpointDir = new File(dir, "q1_checkpointDir").getCanonicalPath + val q1_outputDir = new File(dir, "q1_outputDir").getCanonicalPath + val q1 = + q1_source + .toDF() + .writeStream + .option("checkpointLocation", q1_checkpointDir) + .format("text") + .start(q1_outputDir) + + // q2 is a streaming query that reads q1's text outputs + val q2 = createFileStream("text", q1_outputDir).filter($"value" contains "keep") + + def q1AddData(data: String*): StreamAction = + Execute { _ => + q1_source.addData(data) + q1.processAllAvailable() + } + def q2ProcessAllAvailable(): StreamAction = Execute { q2 => q2.processAllAvailable() } + + testStream(q2)( + // batch 0 + q1AddData("drop1", "keep2"), + q2ProcessAllAvailable(), + CheckAnswer("keep2"), + + // batch 1 + Assert { + // create a text file that won't be on q1's sink log + // thus even if its contents contains "keep", it should NOT appear in q2's answer + val shouldNotKeep = new File(q1_outputDir, "should_not_keep.txt") + stringToFile(shouldNotKeep, "should_not_keep!!!") + shouldNotKeep.exists() + }, + q1AddData("keep3"), + q2ProcessAllAvailable(), + CheckAnswer("keep2", "keep3"), + + // batch 2: check that things work well when the sink log gets compacted + q1AddData("keep4"), + Assert { + // compact interval is 3, so file "2.compact" should exist + new File(q1_outputDir, s"${FileStreamSink.metadataDir}/2.compact").exists() + }, + q2ProcessAllAvailable(), + CheckAnswer("keep2", "keep3", "keep4"), + + // stop q1 manually --- End diff -- fixed
--- 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