diff options
author | Sean Zhong <seanzhong@databricks.com> | 2016-08-16 15:51:30 +0800 |
---|---|---|
committer | Wenchen Fan <wenchen@databricks.com> | 2016-08-16 15:51:30 +0800 |
commit | 7b65030e7a0af3a0bd09370fb069d659b36ff7f0 (patch) | |
tree | c820a00facee5871059e8412c23125823944b838 /docs | |
parent | 7de30d6e9e5d3020d2ba8c2ce08893d9cd822b56 (diff) | |
download | spark-7b65030e7a0af3a0bd09370fb069d659b36ff7f0.tar.gz spark-7b65030e7a0af3a0bd09370fb069d659b36ff7f0.tar.bz2 spark-7b65030e7a0af3a0bd09370fb069d659b36ff7f0.zip |
[SPARK-17034][SQL] adds expression UnresolvedOrdinal to represent the ordinals in GROUP BY or ORDER BY
## What changes were proposed in this pull request?
This PR adds expression `UnresolvedOrdinal` to represent the ordinal in GROUP BY or ORDER BY, and fixes the rules when resolving ordinals.
Ordinals in GROUP BY or ORDER BY like `1` in `order by 1` or `group by 1` should be considered as unresolved before analysis. But in current code, it uses `Literal` expression to store the ordinal. This is inappropriate as `Literal` itself is a resolved expression, it gives the user a wrong message that the ordinals has already been resolved.
### Before this change
Ordinal is stored as `Literal` expression
```
scala> sc.setLogLevel("TRACE")
scala> sql("select a from t group by 1 order by 1")
...
'Sort [1 ASC], true
+- 'Aggregate [1], ['a]
+- 'UnresolvedRelation `t
```
For query:
```
scala> Seq(1).toDF("a").createOrReplaceTempView("t")
scala> sql("select count(a), a from t group by 2 having a > 0").show
```
During analysis, the intermediate plan before applying rule `ResolveAggregateFunctions` is:
```
'Filter ('a > 0)
+- Aggregate [2], [count(1) AS count(1)#83L, a#81]
+- LocalRelation [value#7 AS a#9]
```
Before this PR, rule `ResolveAggregateFunctions` believes all expressions of `Aggregate` have already been resolved, and tries to resolve the expressions in `Filter` directly. But this is wrong, as ordinal `2` in Aggregate is not really resolved!
### After this change
Ordinals are stored as `UnresolvedOrdinal`.
```
scala> sc.setLogLevel("TRACE")
scala> sql("select a from t group by 1 order by 1")
...
'Sort [unresolvedordinal(1) ASC], true
+- 'Aggregate [unresolvedordinal(1)], ['a]
+- 'UnresolvedRelation `t`
```
## How was this patch tested?
Unit tests.
Author: Sean Zhong <seanzhong@databricks.com>
Closes #14616 from clockfly/spark-16955.
Diffstat (limited to 'docs')
0 files changed, 0 insertions, 0 deletions