Github user tdas commented on a diff in the pull request: https://github.com/apache/spark/pull/15949#discussion_r89739836 --- Diff: sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamingAggregationSuite.scala --- @@ -235,4 +239,85 @@ class StreamingAggregationSuite extends StreamTest with BeforeAndAfterAll { CheckLastBatch(("a", 30), ("b", 3), ("c", 1)) ) } + + test("prune results by current_time, complete mode") { + import testImplicits._ + import StreamingAggregationSuite._ + clock = new StreamManualClock + + val inputData = MemoryStream[Long] + + val aggregated = + inputData.toDF() + .groupBy($"value") + .agg(count("*")) + .where('value >= current_timestamp().cast("long") - 10L) + + testStream(aggregated, Complete)( + StartStream(ProcessingTime("10 seconds"), triggerClock = clock), + + // advance clock to 10 seconds + AddData(inputData, 0L, 5L, 5L, 10L), + AdvanceManualClock(10 * 1000), + CheckLastBatch((0L, 1), (5L, 2), (10L, 1)), + + // advance clock to 20 seconds, should retain keys >= 10 + AddData(inputData, 15L, 15L, 20L), + AdvanceManualClock(10 * 1000), + CheckLastBatch((10L, 1), (15L, 2), (20L, 1)), + + // advance clock to 30 seconds, should retain keys >= 20 + AddData(inputData, 0L), + AdvanceManualClock(10 * 1000), + CheckLastBatch((20L, 1)), + + // advance clock to 40 seconds, should retain keys >= 30 + AddData(inputData, 25L, 30L, 40L, 45L), + AdvanceManualClock(10 * 1000), + CheckLastBatch((30L, 1), (40L, 1), (45L, 1)) + ) + } + + + test("prune results by current_date, complete mode") { + import testImplicits._ + import StreamingAggregationSuite._ + clock = new StreamManualClock + val tz = TimeZone.getDefault.getID + val inputData = MemoryStream[Long] + val aggregated = + inputData.toDF() + .select(to_utc_timestamp(from_unixtime('value * DateTimeUtils.SECONDS_PER_DAY), tz)) + .toDF("value") + .groupBy($"value") + .agg(count("*")) + // .select('value, date_sub(current_date(), 10).cast("timestamp").alias("t")) + // .select('value, 't, 'value >= 't) + .where($"value".cast("date") >= date_sub(current_date(), 10)) + .select(($"value".cast("long") / DateTimeUtils.SECONDS_PER_DAY).cast("long"), $"count(1)") + testStream(aggregated, Complete)( + StartStream(ProcessingTime("10 day"), triggerClock = clock), + // advance clock to 10 days, should retain all keys + AddData(inputData, 0L, 5L, 5L, 10L), + AdvanceManualClock(DateTimeUtils.MILLIS_PER_DAY * 10), + CheckLastBatch((0L, 1), (5L, 2), (10L, 1)), + // advance clock to 20 days, should retain keys >= 10 + AddData(inputData, 15L, 15L, 20L), + AdvanceManualClock(DateTimeUtils.MILLIS_PER_DAY * 10), + CheckLastBatch((10L, 1), (15L, 2), (20L, 1)), + // advance clock to 30 days, should retain keys >= 20 + AddData(inputData, 0L), + AdvanceManualClock(DateTimeUtils.MILLIS_PER_DAY * 10), + CheckLastBatch((20L, 1)), + // advance clock to 40 seconds, should retain keys >= 30 --- End diff -- 40 seconds -> days
--- 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