@@ -239,37 +239,43 @@ trait HiveTypeCoercion {
239239 a.makeCopy(Array (a.left, Cast (a.right, DoubleType )))
240240
241241 // we should cast all timestamp/date/string compare into string compare
242- case p : BinaryPredicate if p.left.dataType == StringType
243- && p.right.dataType == DateType =>
242+ case p : BinaryComparison if p.left.dataType == StringType &&
243+ p.right.dataType == DateType =>
244244 p.makeCopy(Array (p.left, Cast (p.right, StringType )))
245- case p : BinaryPredicate if p.left.dataType == DateType
246- && p.right.dataType == StringType =>
245+ case p : BinaryComparison if p.left.dataType == DateType &&
246+ p.right.dataType == StringType =>
247247 p.makeCopy(Array (Cast (p.left, StringType ), p.right))
248- case p : BinaryPredicate if p.left.dataType == StringType
249- && p.right.dataType == TimestampType =>
248+ case p : BinaryComparison if p.left.dataType == StringType &&
249+ p.right.dataType == TimestampType =>
250250 p.makeCopy(Array (p.left, Cast (p.right, StringType )))
251- case p : BinaryPredicate if p.left.dataType == TimestampType
252- && p.right.dataType == StringType =>
251+ case p : BinaryComparison if p.left.dataType == TimestampType &&
252+ p.right.dataType == StringType =>
253253 p.makeCopy(Array (Cast (p.left, StringType ), p.right))
254- case p : BinaryPredicate if p.left.dataType == TimestampType
255- && p.right.dataType == DateType =>
254+ case p : BinaryComparison if p.left.dataType == TimestampType &&
255+ p.right.dataType == DateType =>
256256 p.makeCopy(Array (Cast (p.left, StringType ), Cast (p.right, StringType )))
257- case p : BinaryPredicate if p.left.dataType == DateType
258- && p.right.dataType == TimestampType =>
257+ case p : BinaryComparison if p.left.dataType == DateType &&
258+ p.right.dataType == TimestampType =>
259259 p.makeCopy(Array (Cast (p.left, StringType ), Cast (p.right, StringType )))
260260
261- case p : BinaryPredicate if p.left.dataType == StringType && p.right.dataType != StringType =>
261+ case p : BinaryComparison if p.left.dataType == StringType &&
262+ p.right.dataType != StringType =>
262263 p.makeCopy(Array (Cast (p.left, DoubleType ), p.right))
263- case p : BinaryPredicate if p.left.dataType != StringType && p.right.dataType == StringType =>
264+ case p : BinaryComparison if p.left.dataType != StringType &&
265+ p.right.dataType == StringType =>
264266 p.makeCopy(Array (p.left, Cast (p.right, DoubleType )))
265267
266- case i @ In (a, b) if a.dataType == DateType && b.forall(_.dataType == StringType ) =>
268+ case i @ In (a, b) if a.dataType == DateType &&
269+ b.forall(_.dataType == StringType ) =>
267270 i.makeCopy(Array (Cast (a, StringType ), b))
268- case i @ In (a, b) if a.dataType == TimestampType && b.forall(_.dataType == StringType ) =>
271+ case i @ In (a, b) if a.dataType == TimestampType &&
272+ b.forall(_.dataType == StringType ) =>
269273 i.makeCopy(Array (Cast (a, StringType ), b))
270- case i @ In (a, b) if a.dataType == DateType && b.forall(_.dataType == TimestampType ) =>
274+ case i @ In (a, b) if a.dataType == DateType &&
275+ b.forall(_.dataType == TimestampType ) =>
271276 i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
272- case i @ In (a, b) if a.dataType == TimestampType && b.forall(_.dataType == DateType ) =>
277+ case i @ In (a, b) if a.dataType == TimestampType &&
278+ b.forall(_.dataType == DateType ) =>
273279 i.makeCopy(Array (Cast (a, StringType ), b.map(Cast (_, StringType ))))
274280
275281 case Sum (e) if e.dataType == StringType =>
@@ -420,19 +426,19 @@ trait HiveTypeCoercion {
420426 )
421427
422428 case LessThan (e1 @ DecimalType .Expression (p1, s1),
423- e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
429+ e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
424430 LessThan (Cast (e1, DecimalType .Unlimited ), Cast (e2, DecimalType .Unlimited ))
425431
426432 case LessThanOrEqual (e1 @ DecimalType .Expression (p1, s1),
427- e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
433+ e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
428434 LessThanOrEqual (Cast (e1, DecimalType .Unlimited ), Cast (e2, DecimalType .Unlimited ))
429435
430436 case GreaterThan (e1 @ DecimalType .Expression (p1, s1),
431- e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
437+ e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
432438 GreaterThan (Cast (e1, DecimalType .Unlimited ), Cast (e2, DecimalType .Unlimited ))
433439
434440 case GreaterThanOrEqual (e1 @ DecimalType .Expression (p1, s1),
435- e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
441+ e2 @ DecimalType .Expression (p2, s2)) if p1 != p2 || s1 != s2 =>
436442 GreaterThanOrEqual (Cast (e1, DecimalType .Unlimited ), Cast (e2, DecimalType .Unlimited ))
437443
438444 // Promote integers inside a binary expression with fixed-precision decimals to decimals,
@@ -481,8 +487,8 @@ trait HiveTypeCoercion {
481487 // No need to change the EqualNullSafe operators, too
482488 case e : EqualNullSafe => e
483489 // Otherwise turn them to Byte types so that there exists and ordering.
484- case p : BinaryComparison
485- if p.left.dataType == BooleanType && p.right.dataType == BooleanType =>
490+ case p : BinaryComparison if p.left.dataType == BooleanType &&
491+ p.right.dataType == BooleanType =>
486492 p.makeCopy(Array (Cast (p.left, ByteType ), Cast (p.right, ByteType )))
487493 }
488494 }
@@ -564,10 +570,6 @@ trait HiveTypeCoercion {
564570 case Sum (e @ TimestampType ()) => Sum (Cast (e, DoubleType ))
565571 case Average (e @ TimestampType ()) => Average (Cast (e, DoubleType ))
566572
567- // Compatible with Hive
568- case Substring (e, start, len) if e.dataType != StringType =>
569- Substring (Cast (e, StringType ), start, len)
570-
571573 // Coalesce should return the first non-null value, which could be any column
572574 // from the list. So we need to make sure the return type is deterministic and
573575 // compatible with every child column.
0 commit comments