Github user zsxwing commented on a diff in the pull request:

    https://github.com/apache/spark/pull/15702#discussion_r86235177
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/streaming/WatermarkSuite.scala ---
    @@ -0,0 +1,181 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.spark.sql.streaming
    +
    +import org.scalatest.BeforeAndAfter
    +
    +import org.apache.spark.internal.Logging
    +import org.apache.spark.sql.AnalysisException
    +import org.apache.spark.sql.execution.streaming._
    +import org.apache.spark.sql.functions.{count, window}
    +
    +class WatermarkSuite extends StreamTest with BeforeAndAfter with Logging {
    +
    +  import testImplicits._
    +
    +  after {
    +    sqlContext.streams.active.foreach(_.stop())
    +  }
    +
    +  test("error on bad column") {
    +    val inputData = MemoryStream[Int].toDF()
    +    val e = intercept[AnalysisException] {
    +      inputData.withWatermark("badColumn", "1 minute")
    +    }
    +    assert(e.getMessage contains "badColumn")
    +  }
    +
    +  test("watermark metric") {
    +    val inputData = MemoryStream[Int]
    +
    +    val windowedAggregation = inputData.toDF()
    +        .withColumn("eventTime", $"value".cast("timestamp"))
    +        .withWatermark("eventTime", "10 seconds")
    +        .groupBy(window($"eventTime", "5 seconds") as 'window)
    +        .agg(count("*") as 'count)
    +        .select($"window".getField("start").cast("long").as[Long], 
$"count".as[Long])
    +
    +    testStream(windowedAggregation)(
    +      AddData(inputData, 15),
    +      AssertOnLastQueryStatus { status =>
    +        status.triggerDetails.get(StreamMetrics.EVENT_TIME_WATERMARK) === 
"5000"
    +      },
    +      AddData(inputData, 15),
    +      AssertOnLastQueryStatus { status =>
    +        status.triggerDetails.get(StreamMetrics.EVENT_TIME_WATERMARK) === 
"5000"
    +      },
    +      AddData(inputData, 25),
    +      AssertOnLastQueryStatus { status =>
    +        status.triggerDetails.get(StreamMetrics.EVENT_TIME_WATERMARK) === 
"15000"
    +      }
    +    )
    +  }
    +
    +  test("append-mode watermark aggregation") {
    +    val inputData = MemoryStream[Int]
    +
    +    val windowedAggregation = inputData.toDF()
    +      .withColumn("eventTime", $"value".cast("timestamp"))
    +      .withWatermark("eventTime", "10 seconds")
    +      .groupBy(window($"eventTime", "5 seconds") as 'window)
    +      .agg(count("*") as 'count)
    +      .select($"window".getField("start").cast("long").as[Long], 
$"count".as[Long])
    +
    +    testStream(windowedAggregation)(
    +      AddData(inputData, 10, 11, 12, 13, 14, 15),
    +      CheckAnswer(),
    +      AddData(inputData, 25), // Advance watermark to 15 seconds
    +      CheckAnswer(),
    +      AddData(inputData, 25), // Evict items less than previous watermark.
    +      CheckAnswer((10, 5))
    +    )
    +  }
    +
    +  ignore("recovery") {
    +    val inputData = MemoryStream[Int]
    +
    +    val windowedAggregation = inputData.toDF()
    +        .withColumn("eventTime", $"value".cast("timestamp"))
    +        .withWatermark("eventTime", "10 seconds")
    +        .groupBy(window($"eventTime", "5 seconds") as 'window)
    +        .agg(count("*") as 'count)
    +        .select($"window".getField("start").cast("long").as[Long], 
$"count".as[Long])
    +
    +    testStream(windowedAggregation)(
    +      AddData(inputData, 10, 11, 12, 13, 14, 15),
    +      CheckAnswer(),
    +      AddData(inputData, 25), // Advance watermark to 15 seconds
    +      StopStream,
    +      StartStream(),
    +      CheckAnswer(),
    +      AddData(inputData, 25), // Evict items less than previous watermark.
    +      StopStream,
    +      StartStream(),
    +      CheckAnswer((10, 5))
    +    )
    +  }
    +
    +  test("dropping old data") {
    +    val inputData = MemoryStream[Int]
    +
    +    val windowedAggregation = inputData.toDF()
    +        .withColumn("eventTime", $"value".cast("timestamp"))
    +        .withWatermark("eventTime", "10 seconds")
    +        .groupBy(window($"eventTime", "5 seconds") as 'window)
    +        .agg(count("*") as 'count)
    +        .select($"window".getField("start").cast("long").as[Long], 
$"count".as[Long])
    +
    +    testStream(windowedAggregation)(
    +      AddData(inputData, 10, 11, 12),
    +      CheckAnswer(),
    +      AddData(inputData, 25),     // Advance watermark to 15 seconds
    +      CheckAnswer(),
    +      AddData(inputData, 25),     // Evict items less than previous 
watermark.
    +      CheckAnswer((10, 3)),
    +      AddData(inputData, 10),     // 10 is later than 15 second watermark
    +      CheckAnswer((10, 3)),
    +      AddData(inputData, 25),     // 10 is later than 15 second watermark
    --- End diff --
    
    nit: the comment is wrong


---
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

Reply via email to