viirya commented on a change in pull request #35680:
URL: https://github.com/apache/spark/pull/35680#discussion_r836810791
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameSessionWindowingSuite.scala
##########
@@ -495,4 +495,65 @@ class DataFrameSessionWindowingSuite extends QueryTest
with SharedSparkSession
validateWindowColumnInSchema(schema2, "session")
}
}
+
+ test("SPARK-38349: No need to filter events when gapDuration greater than
0") {
+ // negative value
+ val df1 = Seq(
+ ("2016-03-27 19:39:30", 1, "a")).toDF("time", "value", "id")
+ .groupBy(session_window($"time", "-5 seconds"))
+ .agg(count("*").as("counts"))
+ .orderBy($"session_window.start".asc)
+ .select($"session_window.start".cast("string"),
$"session_window.end".cast("string"),
+ $"counts")
+
+ val filter1 = df1.queryExecution.optimizedPlan.find(_.isInstanceOf[Filter])
+ assert(filter1.isDefined)
+ val exist1 = filter1.filter(_.toString.contains(">"))
+ assert(exist1.nonEmpty, "Need to filter windows when gapDuration less than
0")
+
+ // positive value
+ val df2 = Seq(
+ ("2016-03-27 19:39:40", 2, "a")).toDF("time", "value", "id")
+ .groupBy(session_window($"time", "5 seconds"))
+ .agg(count("*").as("counts"))
+ .orderBy($"session_window.start".asc)
+ .select($"session_window.start".cast("string"),
$"session_window.end".cast("string"),
+ $"counts")
+
+ val filter2 = df2.queryExecution.optimizedPlan.find(_.isInstanceOf[Filter])
+ assert(filter2.isDefined)
+ val exist2 = filter2.filter(_.toString.contains(">"))
+ assert(exist2.isEmpty, "No need to filter windows when gapDuration value
greater than 0")
+
+ // case when
+ val df3 = Seq(
+ ("2016-03-27 19:39:40", 2, "a")).toDF("time", "value", "id")
+ .groupBy(session_window($"time",
+ when(col("time").equalTo("1"), "5 seconds")
+ .when(col("time").equalTo("2"), "10 seconds")
+ .otherwise("10 seconds")))
+ .agg(count("*").as("counts"))
+ .orderBy($"session_window.start".asc)
+ .select($"session_window.start".cast("string"),
$"session_window.end".cast("string"),
+ $"counts")
+
+ val filter3 = df3.queryExecution.optimizedPlan.find(_.isInstanceOf[Filter])
+ assert(filter3.isDefined)
+ val exist3 = filter3.filter(_.toString.contains(">"))
Review comment:
We shouldn't rely on string comparison to check query plan here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]