Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/21470#discussion_r192274753
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala
---
@@ -803,18 +803,60 @@ object TypeCoercion {
e.copy(left = Cast(e.left, TimestampType))
}
- case b @ BinaryOperator(left, right) if left.dataType !=
right.dataType =>
- findTightestCommonType(left.dataType, right.dataType).map {
commonType =>
- if (b.inputType.acceptsType(commonType)) {
- // If the expression accepts the tightest common type, cast to
that.
- val newLeft = if (left.dataType == commonType) left else
Cast(left, commonType)
- val newRight = if (right.dataType == commonType) right else
Cast(right, commonType)
- b.withNewChildren(Seq(newLeft, newRight))
- } else {
- // Otherwise, don't do anything with the expression.
- b
- }
- }.getOrElse(b) // If there is no applicable conversion, leave
expression unchanged.
+ case b @ BinaryOperator(left, right)
+ if !BinaryOperator.sameType(left.dataType, right.dataType) =>
+ (left.dataType, right.dataType) match {
+ case (StructType(fields1), StructType(fields2)) =>
+ val commonTypes =
scala.collection.mutable.ArrayBuffer.empty[DataType]
+ val len = fields1.length
+ var i = 0
+ var continue = fields1.length == fields2.length
+ while (i < len && continue) {
+ val commonType = findTightestCommonType(fields1(i).dataType,
fields2(i).dataType)
--- End diff --
if we don't want to support type coercion, we can change this line to use
`fields1(i).dataType == fields2(i).dataType`
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]