Skip to content

Commit

Permalink
Add canEquals function
Browse files Browse the repository at this point in the history
  • Loading branch information
hvanhovell committed Nov 22, 2016
1 parent a1bd6e1 commit d570c84
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ object Equality {
case EqualNullSafe(l, r) => Some((l, r))
case _ => None
}

def canEquals(dataType: DataType): Boolean = dataType.existsRecursively {
case m: MapType => m.ordered
case _ => true
}
}

@ExpressionDescription(
Expand All @@ -417,7 +422,7 @@ case class EqualTo(left: Expression, right: Expression)
case TypeCheckResult.TypeCheckSuccess =>
// TODO: although map type is not orderable, technically map type should be able to be used
// in equality comparison, remove this type check once we support it.
if (left.dataType.existsRecursively(_.isInstanceOf[MapType])) {
if (!Equality.canEquals(left.dataType)) {
TypeCheckResult.TypeCheckFailure("Cannot use map type in EqualTo, but the actual " +
s"input type is ${left.dataType.catalogString}.")
} else {
Expand Down Expand Up @@ -460,7 +465,7 @@ case class EqualNullSafe(left: Expression, right: Expression) extends BinaryComp
case TypeCheckResult.TypeCheckSuccess =>
// TODO: although map type is not orderable, technically map type should be able to be used
// in equality comparison, remove this type check once we support it.
if (left.dataType.existsRecursively(_.isInstanceOf[MapType])) {
if (!Equality.canEquals(left.dataType)) {
TypeCheckResult.TypeCheckFailure("Cannot use map type in EqualNullSafe, but the actual " +
s"input type is ${left.dataType.catalogString}.")
} else {
Expand Down

0 comments on commit d570c84

Please sign in to comment.