You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2019/05/27 03:44:21 UTC

[GitHub] [spark] cryeo commented on a change in pull request #24335: [SPARK-27425][SQL] Add count_if functions

cryeo commented on a change in pull request #24335: [SPARK-27425][SQL] Add count_if functions
URL: https://github.com/apache/spark/pull/24335#discussion_r287638355
 
 

 ##########
 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:
   OK. I'll add it.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org