ychr commented on a change in pull request #24335: [SPARK-27425][SQL] Add
count_if function
URL: https://github.com/apache/spark/pull/24335#discussion_r291725436
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -894,4 +894,28 @@ class DataFrameAggregateSuite extends QueryTest with
SharedSQLContext {
error.message.contains("function min_by does not support ordering on
type map<int,string>"))
}
}
+
+ test("count_if") {
+ withTempView("tempView") {
+ Seq(("a", None), ("a", Some(1)), ("a", Some(2)), ("a", Some(3)),
+ ("b", None), ("b", Some(4)), ("b", Some(5)), ("b", Some(6)))
+ .toDF("x", "y")
+ .createOrReplaceTempView("tempView")
+
+ checkAnswer(
+ sql("SELECT COUNT_IF(NULL), COUNT_IF(y % 2 = 0), COUNT_IF(y % 2 <> 0),
" +
+ "COUNT_IF(y IS NULL) FROM tempView"),
+ Row(0L, 3L, 3L, 2L))
+
+ checkAnswer(
+ sql("SELECT x, COUNT_IF(NULL), COUNT_IF(y % 2 = 0), COUNT_IF(y % 2 <>
0), " +
+ "COUNT_IF(y IS NULL) FROM tempView GROUP BY x"),
+ Row("a", 0L, 1L, 2L, 1L) :: Row("b", 0L, 2L, 1L, 1L) :: Nil)
Review comment:
Ok, I just added additional cases.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]