Skip to content

Commit

Permalink
[SPARK-27425] Modify version, documentation and style
Browse files Browse the repository at this point in the history
  • Loading branch information
cryeo committed May 21, 2019
1 parent d7370ed commit 45215f9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,12 @@ import org.apache.spark.sql.types._
""",
examples = """
Examples:
> SELECT _FUNC_(col % 2 = 0) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
2
> SELECT _FUNC_(col % 2 = 0) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
2
> SELECT _FUNC_(col IS NULL) FROM VALUES (NULL), (0), (1), (2), (3) AS tab(col);
1
""",
since = "2.5.0")
since = "3.0.0")
case class CountIf(child: Expression) extends DeclarativeAggregate {

override def children: Seq[Expression] = child :: Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,22 @@ class CountIfSuite extends SparkFunSuite {
val result1: InternalRow = evaluator.update(
InternalRow(true),
InternalRow(false),
InternalRow(true)
)
InternalRow(true))
assert(result1 === InternalRow(2L))

// update with nulls
val result2: InternalRow = evaluator.update(
InternalRow(null),
InternalRow(null),
InternalRow(null)
)
InternalRow(null))
assert(result2 === InternalRow(0L))

// update with non-nulls and nulls
val result: InternalRow = evaluator.update(
InternalRow(null),
InternalRow(true),
InternalRow(null),
InternalRow(false)
)
InternalRow(false))
assert(result === InternalRow(1L))
}

Expand All @@ -68,16 +65,14 @@ class CountIfSuite extends SparkFunSuite {
val partition1: InternalRow = evaluator.update(
InternalRow(true),
InternalRow(false),
InternalRow(true)
)
InternalRow(true))
assert(evaluator.merge(partition1) === InternalRow(2L))

// merge multiples
val partition2: InternalRow = evaluator.update(
InternalRow(false),
InternalRow(true),
InternalRow(null)
)
InternalRow(null))
assert(evaluator.merge(partition0, partition1) === InternalRow(2L))
assert(evaluator.merge(partition0, partition2) === InternalRow(1L))
assert(evaluator.merge(partition1, partition2) === InternalRow(3L))
Expand All @@ -96,16 +91,14 @@ class CountIfSuite extends SparkFunSuite {
val partition1: InternalRow = evaluator.update(
InternalRow(true),
InternalRow(false),
InternalRow(true)
)
InternalRow(true))
assert(evaluator.eval(partition1) === InternalRow(2L))

// eval after update and merge
val partition2: InternalRow = evaluator.update(
InternalRow(false),
InternalRow(true),
InternalRow(null)
)
InternalRow(null))
val merge: InternalRow = evaluator.merge(partition0, partition1, partition2)
assert(evaluator.eval(merge) === InternalRow(3L))
}
Expand Down
4 changes: 2 additions & 2 deletions sql/core/src/main/scala/org/apache/spark/sql/functions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ object functions {
* Aggregate function: returns the number of true values in a group.
*
* @group agg_funcs
* @since 2.5.0
* @since 3.0.0
*/
def count_if(e: Column): Column = withAggregateFunction {
CountIf(e.expr)
Expand All @@ -387,7 +387,7 @@ object functions {
* Aggregate function: returns the number of true values in a group.
*
* @group agg_funcs
* @since 2.5.0
* @since 3.0.0
*/
def count_if(columnName: String): TypedColumn[Boolean, Long] =
count_if(Column(columnName)).as(ExpressionEncoder[Long]())
Expand Down

0 comments on commit 45215f9

Please sign in to comment.