Github user marmbrus commented on a diff in the pull request:
https://github.com/apache/spark/pull/12008#discussion_r57621079
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameFunctionsSuite.scala ---
@@ -394,4 +394,72 @@ class DataFrameFunctionsSuite extends QueryTest with
SharedSQLContext {
Seq(Row(true), Row(true))
)
}
+
+ test("time windowing") {
+ // 2016-03-27 19:39:34 UTC, 2016-03-27 19:39:56 UTC, 2016-03-27
19:39:27 UTC
+ val df = Seq((1459103974L, 1, "a"), (1459103996L, 2, "a"),
+ (1459103967L, 4, "b")).toDF("time", "value", "id")
+ checkAnswer(
+ df.groupBy(window($"time", "10
seconds")).agg(count("*").as("counts"))
+ .orderBy($"window.start".asc).select("counts"),
+ Seq(Row(1), Row(1), Row(1))
+ )
+ checkAnswer(
+ df.groupBy(window($"time", "10 seconds", "10 seconds", "5 seconds"))
+
.agg(count("*").as("counts")).orderBy($"window.start".asc).select("counts"),
+ Seq(Row(2), Row(1))
+ )
+ checkAnswer(
+ df.groupBy(window($"time", "10 seconds", "10 seconds", "5 seconds"),
$"id")
+
.agg(count("*").as("counts")).orderBy($"window.start".asc).select("counts"),
+ Seq(Row(1), Row(1), Row(1))
+ )
+ checkAnswer(
+ df.groupBy(window($"time", "10 seconds", "3 seconds", "0 second"))
+
.agg(count("*").as("counts")).orderBy($"window.start".asc).select("counts"),
+ // 2016-03-27 19:39:27 UTC -> 4 bins
+ // 2016-03-27 19:39:34 UTC -> 3 bins
+ // 2016-03-27 19:39:56 UTC -> 3 bins
+ Seq(Row(1), Row(1), Row(1), Row(2), Row(1), Row(1), Row(1), Row(1),
Row(1))
+ )
+ checkAnswer(
+ df.select(window($"time", "10 seconds"), $"value")
+ .orderBy($"window.start".asc).select("value"),
+ Seq(Row(4), Row(1), Row(2))
--- End diff --
It might be helpful to separate these into tests named `tumbling`,
`overlapping` etc. Just to make it clearer that we are covering all the cases
well.
---
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 [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]