Skip to content

Commit

Permalink
[SQL] Add an exception for analysis errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
marmbrus committed Feb 6, 2015
1 parent 3d3ecd7 commit 6235db4
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ import org.apache.spark.sql.types.IntegerType
*/
object SimpleAnalyzer extends Analyzer(EmptyCatalog, EmptyFunctionRegistry, true)

/**
* Thrown when a query fails to analyze, usually because the query itself is invalid.
*/
class AnalysisException(message: String) extends Exception(message) with Serializable

/**
* Provides a logical query plan analyzer, which translates [[UnresolvedAttribute]]s and
* [[UnresolvedRelation]]s into fully typed objects using information in a schema [[Catalog]] and
Expand Down Expand Up @@ -81,16 +86,18 @@ class Analyzer(catalog: Catalog,
*/
object CheckResolution extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = {
plan.transform {
plan.transformUp {
case p if p.expressions.exists(!_.resolved) =>
throw new TreeNodeException(p,
s"Unresolved attributes: ${p.expressions.filterNot(_.resolved).mkString(",")}")
val missing = p.expressions.filterNot(_.resolved).map(_.prettyString).mkString(",")
val from = p.inputSet.map(_.name).mkString("{", ", ", "}")

throw new AnalysisException(s"Cannot resolve '$missing' given input columns $from")
case p if !p.resolved && p.childrenResolved =>
throw new TreeNodeException(p, "Unresolved plan found")
throw new AnalysisException(s"Unresolved operator in the query plan ${p.simpleString}")
} match {
// As a backstop, use the root node to check that the entire plan tree is resolved.
case p if !p.resolved =>
throw new TreeNodeException(p, "Unresolved plan in tree")
throw new AnalysisException(s"Unresolved operator in the query plan ${p.simpleString}")
case p => p
}
}
Expand Down

0 comments on commit 6235db4

Please sign in to comment.