aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main
diff options
context:
space:
mode:
authorpetermaxlee <petermaxlee@gmail.com>2016-08-11 01:43:08 -0700
committerReynold Xin <rxin@databricks.com>2016-08-11 01:43:08 -0700
commita7b02db457d5fc663ce6a1ef01bf04689870e6b4 (patch)
treefd52ff812f94761adb03e9610fcc053e14a96120 /sql/catalyst/src/main
parent0db373aaf87991207a7a8a09853b6fa602f0f45b (diff)
downloadspark-a7b02db457d5fc663ce6a1ef01bf04689870e6b4.tar.gz
spark-a7b02db457d5fc663ce6a1ef01bf04689870e6b4.tar.bz2
spark-a7b02db457d5fc663ce6a1ef01bf04689870e6b4.zip
[SPARK-17015][SQL] group-by/order-by ordinal and arithmetic tests
## What changes were proposed in this pull request? This patch adds three test files: 1. arithmetic.sql.out 2. order-by-ordinal.sql 3. group-by-ordinal.sql This includes https://github.com/apache/spark/pull/14594. ## How was this patch tested? This is a test case change. Author: petermaxlee <petermaxlee@gmail.com> Closes #14595 from petermaxlee/SPARK-17015.
Diffstat (limited to 'sql/catalyst/src/main')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala24
1 files changed, 12 insertions, 12 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
index 25202b521a..14a2a323c8 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
@@ -547,8 +547,7 @@ class Analyzer(
case a: Aggregate if containsStar(a.aggregateExpressions) =>
if (conf.groupByOrdinal && a.groupingExpressions.exists(IntegerIndex.unapply(_).nonEmpty)) {
failAnalysis(
- "Group by position: star is not allowed to use in the select list " +
- "when using ordinals in group by")
+ "Star (*) is not allowed in select list when GROUP BY ordinal position is used")
} else {
a.copy(aggregateExpressions = buildExpandedProjectList(a.aggregateExpressions, a.child))
}
@@ -723,9 +722,9 @@ class Analyzer(
if (index > 0 && index <= child.output.size) {
SortOrder(child.output(index - 1), direction)
} else {
- throw new UnresolvedException(s,
- s"Order/sort By position: $index does not exist " +
- s"The Select List is indexed from 1 to ${child.output.size}")
+ s.failAnalysis(
+ s"ORDER BY position $index is not in select list " +
+ s"(valid range is [1, ${child.output.size}])")
}
case o => o
}
@@ -737,17 +736,18 @@ class Analyzer(
if conf.groupByOrdinal && aggs.forall(_.resolved) &&
groups.exists(IntegerIndex.unapply(_).nonEmpty) =>
val newGroups = groups.map {
- case IntegerIndex(index) if index > 0 && index <= aggs.size =>
+ case ordinal @ IntegerIndex(index) if index > 0 && index <= aggs.size =>
aggs(index - 1) match {
case e if ResolveAggregateFunctions.containsAggregate(e) =>
- throw new UnresolvedException(a,
- s"Group by position: the '$index'th column in the select contains an " +
- s"aggregate function: ${e.sql}. Aggregate functions are not allowed in GROUP BY")
+ ordinal.failAnalysis(
+ s"GROUP BY position $index is an aggregate function, and " +
+ "aggregate functions are not allowed in GROUP BY")
case o => o
}
- case IntegerIndex(index) =>
- throw new UnresolvedException(a,
- s"Group by position: '$index' exceeds the size of the select list '${aggs.size}'.")
+ case ordinal @ IntegerIndex(index) =>
+ ordinal.failAnalysis(
+ s"GROUP BY position $index is not in select list " +
+ s"(valid range is [1, ${aggs.size}])")
case o => o
}
Aggregate(newGroups, aggs, child)