Skip to content

Commit 34eb3a4

Browse files
committed
more work
1 parent 6197cd5 commit 34eb3a4

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Analyzer(catalog: Catalog,
8383
operator transformAllExpressions {
8484
case a: Attribute if !a.resolved =>
8585
val from = operator.inputSet.map(_.name).mkString("{", ", ", "}")
86-
failAnalysis(s"cannot resolve '$a' given input columns $from")
86+
failAnalysis(s"cannot resolve '${a.prettyString}' given input columns $from")
8787

8888
case c: Cast if !c.resolved =>
8989
failAnalysis(
@@ -93,13 +93,13 @@ class Analyzer(catalog: Catalog,
9393
failAnalysis(
9494
s"invalid expression ${b.prettyString} " +
9595
s"between ${b.left.simpleString} and ${b.right.simpleString}")
96-
97-
9896
}
9997

10098
operator match {
10199
case f: Filter if f.condition.dataType != BooleanType =>
102-
failAnalysis(s"filter expression '${f.condition.prettyString}' is not a boolean.")
100+
failAnalysis(
101+
s"filter expression '${f.condition.prettyString}' " +
102+
s"of type ${f.condition.dataType.simpleString} is not a boolean.")
103103

104104
case aggregatePlan @ Aggregate(groupingExprs, aggregateExprs, child) =>
105105
def isValidAggregateExpression(expr: Expression): Boolean = expr match {
@@ -118,11 +118,10 @@ class Analyzer(catalog: Catalog,
118118
case Alias(g: GetField, _) => g
119119
})
120120
}.foreach { e =>
121-
failAnalysis(s"expression must be aggregates or be in group by $e")
121+
failAnalysis(
122+
s"expression '${e.prettyString}' is not an aggregate function or in the group by")
122123
}
123124

124-
aggregatePlan
125-
126125
case o if o.children.nonEmpty && !o.references.subsetOf(o.inputSet) =>
127126
val missingAttributes = (o.references -- o.inputSet).map(_.prettyString).mkString(",")
128127
val input = o.inputSet.map(_.prettyString).mkString(",")

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ case class PrettyAttribute(name: String) extends Attribute with trees.LeafNode[E
218218
override def exprId: ExprId = ???
219219
override def eval(input: Row): EvaluatedType = ???
220220
override def nullable: Boolean = ???
221-
override def dataType: DataType = ???
221+
override def dataType: DataType = NullType
222222
}
223223

224224
object VirtualColumn {

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/AnalysisSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,17 @@ class AnalysisSuite extends FunSuite with BeforeAndAfter {
136136
testRelation.select(Literal(1).cast(BinaryType).as('badCast)),
137137
"invalid cast" :: Literal(1).dataType.simpleString :: BinaryType.simpleString :: Nil)
138138

139+
errorTest(
140+
"non-boolean filters",
141+
testRelation.where(Literal(1)),
142+
"filter" :: "'1'" :: "not a boolean" :: Literal(1).dataType.simpleString :: Nil)
143+
144+
errorTest(
145+
"missing group by",
146+
testRelation2.groupBy('a)('b),
147+
"'b'" :: "group by" :: Nil
148+
)
149+
139150
case class UnresolvedTestPlan() extends LeafNode {
140151
override lazy val resolved = false
141152
override def output = Nil

sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,8 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
806806
test("throw errors for non-aggregate attributes with aggregation") {
807807
def checkAggregation(query: String, isInvalidQuery: Boolean = true) {
808808
if (isInvalidQuery) {
809-
val e = intercept[TreeNodeException[LogicalPlan]](sql(query).queryExecution.analyzed)
810-
assert(
811-
e.getMessage.startsWith("Expression not in GROUP BY"),
812-
"Non-aggregate attribute(s) not detected\n")
809+
val e = intercept[AnalysisException](sql(query).queryExecution.analyzed)
810+
assert(e.getMessage contains "group by")
813811
} else {
814812
// Should not throw
815813
sql(query).queryExecution.analyzed

0 commit comments

Comments
 (0)