diff options
author | Dongjoon Hyun <dongjoon@apache.org> | 2016-08-24 21:14:40 +0200 |
---|---|---|
committer | Herman van Hovell <hvanhovell@databricks.com> | 2016-08-24 21:14:40 +0200 |
commit | 40b30fcf453169534cb53d01cd22236210b13005 (patch) | |
tree | 0ef4595336eeed368ce401d73083b8cac8ffd45c /sql/catalyst/src/main | |
parent | 0b3a4be92ca6b38eef32ea5ca240d9f91f68aa65 (diff) | |
download | spark-40b30fcf453169534cb53d01cd22236210b13005.tar.gz spark-40b30fcf453169534cb53d01cd22236210b13005.tar.bz2 spark-40b30fcf453169534cb53d01cd22236210b13005.zip |
[SPARK-16983][SQL] Add `prettyName` for row_number, dense_rank, percent_rank, cume_dist
## What changes were proposed in this pull request?
Currently, two-word window functions like `row_number`, `dense_rank`, `percent_rank`, and `cume_dist` are expressed without `_` in error messages. We had better show the correct names.
**Before**
```scala
scala> sql("select row_number()").show
java.lang.UnsupportedOperationException: Cannot evaluate expression: rownumber()
```
**After**
```scala
scala> sql("select row_number()").show
java.lang.UnsupportedOperationException: Cannot evaluate expression: row_number()
```
## How was this patch tested?
Pass the Jenkins and manual.
Author: Dongjoon Hyun <dongjoon@apache.org>
Closes #14571 from dongjoon-hyun/SPARK-16983.
Diffstat (limited to 'sql/catalyst/src/main')
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala index 6806591f68..b47486f7af 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/windowExpressions.scala @@ -477,7 +477,7 @@ object SizeBasedWindowFunction { the window partition.""") case class RowNumber() extends RowNumberLike { override val evaluateExpression = rowNumber - override def sql: String = "ROW_NUMBER()" + override def prettyName: String = "row_number" } /** @@ -497,7 +497,7 @@ case class CumeDist() extends RowNumberLike with SizeBasedWindowFunction { // return the same value for equal values in the partition. override val frame = SpecifiedWindowFrame(RangeFrame, UnboundedPreceding, CurrentRow) override val evaluateExpression = Divide(Cast(rowNumber, DoubleType), Cast(n, DoubleType)) - override def sql: String = "CUME_DIST()" + override def prettyName: String = "cume_dist" } /** @@ -628,6 +628,8 @@ abstract class RankLike extends AggregateWindowFunction { override val updateExpressions = increaseRank +: increaseRowNumber +: children override val evaluateExpression: Expression = rank + override def sql: String = s"${prettyName.toUpperCase}()" + def withOrder(order: Seq[Expression]): RankLike } @@ -649,7 +651,6 @@ abstract class RankLike extends AggregateWindowFunction { case class Rank(children: Seq[Expression]) extends RankLike { def this() = this(Nil) override def withOrder(order: Seq[Expression]): Rank = Rank(order) - override def sql: String = "RANK()" } /** @@ -674,7 +675,7 @@ case class DenseRank(children: Seq[Expression]) extends RankLike { override val updateExpressions = increaseRank +: children override val aggBufferAttributes = rank +: orderAttrs override val initialValues = zero +: orderInit - override def sql: String = "DENSE_RANK()" + override def prettyName: String = "dense_rank" } /** @@ -701,5 +702,5 @@ case class PercentRank(children: Seq[Expression]) extends RankLike with SizeBase override val evaluateExpression = If(GreaterThan(n, one), Divide(Cast(Subtract(rank, one), DoubleType), Cast(Subtract(n, one), DoubleType)), Literal(0.0d)) - override def sql: String = "PERCENT_RANK()" + override def prettyName: String = "percent_rank" } |