HyukjinKwon commented on a change in pull request #24335: [SPARK-27425][SQL]
Add count_if functions
URL: https://github.com/apache/spark/pull/24335#discussion_r287203613
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameAggregateSuite.scala
##########
@@ -894,4 +894,29 @@ class DataFrameAggregateSuite extends QueryTest with
SharedSQLContext {
error.message.contains("function min_by does not support ordering on
type map<int,string>"))
}
}
+
+ test("SPARK-27425: count_if function") {
+ def checkError(df: => DataFrame): Unit = {
+ val thrownException = the [AnalysisException] thrownBy
df.queryExecution.analyzed
+ assert(thrownException.message.contains("function count_if requires
boolean type"))
+ }
+
+ checkAnswer(
+ testData.agg(count_if('key % 2 === 0), count_if('key > 50),
count_if('key < 50)),
+ Row(50L, 50L, 49L))
+ checkAnswer(
+ sql("SELECT COUNT_IF(key % 2 = 0), COUNT_IF(key > 50), COUNT_IF(key <
50) FROM testData"),
+ Row(50L, 50L, 49L))
+
+ checkAnswer(
+ testData2.groupBy('a).agg(count_if('b % 2 === 0)),
+ Seq(Row(1, 1L), Row(2, 1L), Row(3, 1L)))
+ checkAnswer(
+ sql("SELECT a, COUNT_IF(b % 2 = 0) FROM testData2 GROUP BY a"),
+ Seq(Row(1, 1L), Row(2, 1L), Row(3, 1L)))
Review comment:
Can we add a test with `null` as well?
----------------------------------------------------------------
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]