Skip to content

Commit 9e194b5

Browse files
committed
fix
1 parent b793d06 commit 9e194b5

File tree

3 files changed

+10
-17
lines changed

3 files changed

+10
-17
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
118118
ReplaceExpressions,
119119
ComputeCurrentTime,
120120
GetCurrentDatabase(sessionCatalog),
121-
RewriteUnevaluableAggregates,
122121
RewriteDistinctAggregates,
123122
ReplaceDeduplicateWithAggregate) ::
124123
//////////////////////////////////////////////////////////////////////////////////////////
@@ -207,8 +206,7 @@ abstract class Optimizer(sessionCatalog: SessionCatalog)
207206
PullupCorrelatedPredicates.ruleName ::
208207
RewriteCorrelatedScalarSubquery.ruleName ::
209208
RewritePredicateSubquery.ruleName ::
210-
PullOutPythonUDFInJoinCondition.ruleName ::
211-
RewriteUnevaluableAggregates.ruleName :: Nil
209+
PullOutPythonUDFInJoinCondition.ruleName :: Nil
212210

213211
/**
214212
* Optimize all the subqueries inside expression.

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

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,18 @@ import org.apache.spark.sql.types._
2929

3030

3131
/**
32-
* Finds all [[RuntimeReplaceable]] expressions and replace them with the expressions that can
33-
* be evaluated. This is mainly used to provide compatibility with other databases.
34-
* For example, we use this to support "nvl" by replacing it with "coalesce".
32+
* Finds all the expressions that are unevaluable and replace/rewrite them with semantically
33+
* equivalent expressions that can be evaluated. Currently we replace two kinds of expressions :
34+
* 1) [[RuntimeReplaceable]] expressions
35+
* 2) [[UnevaluableAggrgate]] expressions such as Every, Some, Any
36+
* This is mainly used to provide compatibility with other databases.
37+
* Few examples are :
38+
* we use this to support "nvl" by replacing it with "coalesce".
39+
* we use this to replace Every and Any with Min and Max respectively.
3540
*/
3641
object ReplaceExpressions extends Rule[LogicalPlan] {
3742
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
3843
case e: RuntimeReplaceable => e.child
39-
}
40-
}
41-
42-
/**
43-
* Rewrites the aggregates expressions by replacing them with another. This is mainly used to
44-
* provide compatibiity with other databases. For example, we use this to support
45-
* Every, Any/Some by rewriting them to Min, Max respectively.
46-
*/
47-
object RewriteUnevaluableAggregates extends Rule[LogicalPlan] {
48-
def apply(plan: LogicalPlan): LogicalPlan = plan transformAllExpressions {
4944
case SomeAgg(arg) => Max(arg)
5045
case AnyAgg(arg) => Max(arg)
5146
case EveryAgg(arg) => Min(arg)

sql/core/src/test/resources/sql-tests/inputs/group-by.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ SELECT any(1L);
137137
-- input type checking String
138138
SELECT every("true");
139139

140-
-- every/some/any aggregates are not supported as windows expression.
140+
-- every/some/any aggregates are supported as windows expression.
141141
SELECT k, v, every(v) OVER (PARTITION BY k ORDER BY v) FROM test_agg;
142142
SELECT k, v, some(v) OVER (PARTITION BY k ORDER BY v) FROM test_agg;
143143
SELECT k, v, any(v) OVER (PARTITION BY k ORDER BY v) FROM test_agg;

0 commit comments

Comments
 (0)