Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,9 @@ case class Aggregate(

// Whether this Aggregate operator is group only. For example: SELECT a, a FROM t GROUP BY a
private[sql] def groupOnly: Boolean = {
aggregateExpressions.map {
// aggregateExpressions can be empty through Dateset.agg,
// so we should also check groupingExpressions is non empty
groupingExpressions.nonEmpty && aggregateExpressions.map {
case Alias(child, _) => child
case e => e
}.forall(a => groupingExpressions.exists(g => a.semanticEquals(g)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,11 @@ class DataFrameAggregateSuite extends QueryTest
val res = df.select($"d".cast("decimal(12, 2)").as("d")).agg(avg($"d").cast("string"))
checkAnswer(res, Row("9999999999.990000"))
}

test("SPARK-38185: Fix data incorrect if aggregate function is empty") {
val emptyAgg = Map.empty[String, String]
assert(spark.range(2).where("id > 2").agg(emptyAgg).limit(1).count == 1)
}
}

case class B(c: Option[Double])
Expand Down