@@ -666,6 +666,19 @@ object HiveTypeCoercion {
666666 // Skip nodes who's children have not been resolved yet.
667667 case e if ! e.childrenResolved => e
668668
669+ case b @ BinaryOperator (left, right) if left.dataType != right.dataType =>
670+ findTightestCommonTypeOfTwo(left.dataType, right.dataType).map { commonType =>
671+ if (b.inputType.acceptsType(commonType)) {
672+ // If the expression accepts the tighest common type, cast to that.
673+ val newLeft = if (left.dataType == commonType) left else Cast (left, commonType)
674+ val newRight = if (right.dataType == commonType) right else Cast (right, commonType)
675+ b.makeCopy(Array (newLeft, newRight))
676+ } else {
677+ // Otherwise, don't do anything with the expression.
678+ b
679+ }
680+ }.getOrElse(b) // If there is no applicable conversion, leave expression unchanged.
681+
669682 case e : ImplicitCastInputTypes if e.inputTypes.nonEmpty =>
670683 val children : Seq [Expression ] = e.children.zip(e.inputTypes).map { case (in, expected) =>
671684 // If we cannot do the implicit cast, just use the original input.
@@ -684,28 +697,6 @@ object HiveTypeCoercion {
684697 }
685698 }
686699 e.withNewChildren(children)
687-
688- case b @ BinaryOperator (left, right)
689- if left.dataType == NullType && right.dataType == NullType &&
690- ! b.inputType.acceptsType(NullType ) =>
691- // If both inputs are null type (from null literals), cast the null type into some
692- // specific type the expression expects, so expressions don't need to handle NullType
693- val newLeft = Cast (left, b.inputType.defaultConcreteType)
694- val newRight = Cast (right, b.inputType.defaultConcreteType)
695- b.makeCopy(Array (newLeft, newRight))
696-
697- case b @ BinaryOperator (left, right) if left.dataType != right.dataType =>
698- findTightestCommonTypeOfTwo(left.dataType, right.dataType).map { commonType =>
699- if (b.inputType.acceptsType(commonType)) {
700- // If the expression accepts the tighest common type, cast to that.
701- val newLeft = if (left.dataType == commonType) left else Cast (left, commonType)
702- val newRight = if (right.dataType == commonType) right else Cast (right, commonType)
703- b.makeCopy(Array (newLeft, newRight))
704- } else {
705- // Otherwise, don't do anything with the expression.
706- b
707- }
708- }.getOrElse(b) // If there is no applicable conversion, leave expression unchanged.
709700 }
710701
711702 /**
0 commit comments