Skip to content

Commit 67fc72d

Browse files
rootroot
authored andcommitted
fix some code style
1 parent c5b3a3d commit 67fc72d

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/RewriteDistinctAggregates.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,12 @@ object RewriteDistinctAggregates extends Rule[LogicalPlan] {
115115
}
116116

117117
// Extract distinct aggregate expressions.
118-
val distinctAggGroups = aggExpressions.filter(_.isDistinct).groupBy{
118+
val distinctAggGroups = aggExpressions.filter(_.isDistinct).groupBy {
119119
e =>
120-
if (e.aggregateFunction.children.exists(!_.foldable)) {
120+
val unfoldableChildren = e.aggregateFunction.children.filter(!_.foldable).toSet
121+
if (unfoldableChildren.nonEmpty) {
121122
// Only expand the unfoldable children
122-
e.aggregateFunction.children.filter(!_.foldable).toSet
123+
unfoldableChildren
123124
} else {
124125
// If aggregateFunction's children are all foldable
125126
// we must expand at least one of the children (here we take the first child),

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveUDFSuite.scala

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -150,21 +150,38 @@ class HiveUDFSuite extends QueryTest with TestHiveSingleton with SQLTestUtils {
150150
}
151151

152152
test("Generic UDAF aggregates") {
153-
checkAnswer(sql("SELECT percentile_approx(2, 0.99999), " +
154-
"sum(distinct 1), count(distinct 1,2,3,4) FROM src LIMIT 1"),
155-
sql("SELECT 2, 1, 1 FROM src LIMIT 1")
156-
.collect().toSeq)
157153

158-
checkAnswer(sql("SELECT ceiling(percentile_approx(distinct key, 0.99999))" +
159-
", count(distinct key), sum(distinct key), " +
160-
"count(distinct 1), sum(distinct 1), sum(1) FROM src LIMIT 1"),
161-
sql("SELECT max(key), count(distinct key), sum(distinct key)," +
162-
" 1, 1, sum(1) FROM src LIMIT 1")
163-
.collect().toSeq)
154+
checkAnswer(sql(
155+
"""
156+
|SELECT percentile_approx(2, 0.99999),
157+
| sum(distinct 1),
158+
| count(distinct 1,2,3,4) FROM src LIMIT 1
159+
""".stripMargin), sql("SELECT 2, 1, 1 FROM src LIMIT 1").collect().toSeq)
160+
161+
checkAnswer(sql(
162+
"""
163+
|SELECT ceiling(percentile_approx(distinct key, 0.99999)),
164+
| count(distinct key),
165+
| sum(distinct key),
166+
| count(distinct 1),
167+
| sum(distinct 1),
168+
| sum(1) FROM src LIMIT 1
169+
""".stripMargin),
170+
sql(
171+
"""
172+
|SELECT max(key),
173+
| count(distinct key),
174+
| sum(distinct key),
175+
| 1, 1, sum(1) FROM src LIMIT 1
176+
""".stripMargin).collect().toSeq)
164177

165-
checkAnswer(sql("SELECT ceiling(percentile_approx(distinct key, 0.9 + 0.09999))" +
166-
", count(distinct key), sum(distinct key), " +
167-
"count(distinct 1), sum(distinct 1), sum(1) FROM src LIMIT 1"),
178+
checkAnswer(sql(
179+
"""
180+
|SELECT ceiling(percentile_approx(distinct key, 0.9 + 0.09999)),
181+
| count(distinct key), sum(distinct key),
182+
| count(distinct 1), sum(distinct 1),
183+
| sum(1) FROM src LIMIT 1
184+
""".stripMargin),
168185
sql("SELECT max(key), count(distinct key), sum(distinct key), 1, 1, sum(1) FROM src LIMIT 1")
169186
.collect().toSeq)
170187

0 commit comments

Comments
 (0)