Skip to content

Commit

Permalink
Improve error reporting for expression data type mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
cloud-fan committed Jun 1, 2015
1 parent a0e46a0 commit cb77e4f
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 250 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ trait CheckAnalysis {
val from = operator.inputSet.map(_.name).mkString(", ")
a.failAnalysis(s"cannot resolve '${a.prettyString}' given input columns $from")

case e: Expression if !e.validInputTypes =>
e.failAnalysis(
s"cannot resolve '${t.prettyString}' due to data type mismatch: " +
e.typeMismatchErrorMessage.get)

case c: Cast if !c.resolved =>
failAnalysis(
s"invalid cast from ${c.child.dataType.simpleString} to ${c.dataType.simpleString}")

case b: BinaryExpression if !b.resolved =>
failAnalysis(
s"invalid expression ${b.prettyString} " +
s"between ${b.left.dataType.simpleString} and ${b.right.dataType.simpleString}")

case WindowExpression(UnresolvedWindowFunction(name, _), _) =>
failAnalysis(
s"Could not resolve window function '$name'. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ trait HiveTypeCoercion {
Union(newLeft, newRight)

// fix decimal precision for expressions
case q => q.transformExpressions {
case q => q.transformExpressionsUp {
// Skip nodes whose children have not been resolved yet
case e if !e.childrenResolved => e

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,16 @@ abstract class Expression extends TreeNode[Expression] {
case (i1, i2) => i1 == i2
}
}

def typeMismatchErrorMessage: Option[String] = None

def validInputTypes: Boolean = typeMismatchErrorMessage.isEmpty
}

abstract class BinaryExpression extends Expression with trees.BinaryNode[Expression] {
self: Product =>

def symbol: String
def symbol: String = sys.error(s"BinaryExpressions must either override toString or symbol")

override def foldable: Boolean = left.foldable && right.foldable

Expand All @@ -106,6 +110,10 @@ abstract class LeafExpression extends Expression with trees.LeafNode[Expression]

abstract class UnaryExpression extends Expression with trees.UnaryNode[Expression] {
self: Product =>

override def foldable: Boolean = child.foldable

override def nullable: Boolean = child.nullable
}

// TODO Semantically we probably not need GroupExpression
Expand All @@ -125,7 +133,9 @@ case class GroupExpression(children: Seq[Expression]) extends Expression {
* so that the proper type conversions can be performed in the analyzer.
*/
trait ExpectsInputTypes {
self: Expression =>

def expectedChildTypes: Seq[DataType]

override def validInputTypes: Boolean = children.map(_.dataType) == expectedChildTypes
}
Loading

0 comments on commit cb77e4f

Please sign in to comment.