Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/3150#discussion_r19997693
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ---
    @@ -37,8 +42,62 @@ case class Cast(child: Expression, dataType: DataType) 
extends UnaryExpression w
         case (BooleanType, DateType)      => true
         case (DateType, _: NumericType)   => true
         case (DateType, BooleanType)      => true
    -    case (_, DecimalType.Fixed(_, _)) => true  // TODO: not all upcasts 
here can really give null
    -    case _                            => child.nullable
    +    case (_, DecimalType.Fixed(_, _)) => true // TODO: not all upcasts 
here can really give null
    +    case _                            => false
    +  }
    +
    +  private[this] def resolvableNullability(from: Boolean, to: Boolean) = 
!from || to
    +
    +  private[this] def resolve(from: DataType, to: DataType): Boolean = {
    +    (from, to) match {
    +      case (from, to) if from == to         => true
    +
    +      case (NullType, _)                    => true
    +
    +      case (_, StringType)                  => true
    +
    +      case (StringType, BinaryType)         => true
    +
    +      case (StringType, BooleanType)        => true
    +      case (DateType, BooleanType)          => true
    +      case (TimestampType, BooleanType)     => true
    +      case (_: NumericType, BooleanType)    => true
    +
    +      case (StringType, TimestampType)      => true
    +      case (BooleanType, TimestampType)     => true
    +      case (DateType, TimestampType)        => true
    +      case (_: NumericType, TimestampType)  => true
    +
    +      case (_, DateType)                    => true
    +
    +      case (StringType, _: NumericType)     => true
    +      case (BooleanType, _: NumericType)    => true
    +      case (DateType, _: NumericType)       => true
    +      case (TimestampType, _: NumericType)  => true
    +      case (_: NumericType, _: NumericType) => true
    +
    +      case (ArrayType(from, fn), ArrayType(to, tn)) =>
    +        resolve(from, to) &&
    +          resolvableNullability(fn || forceNullable(from, to), tn)
    +
    +      case (MapType(fromKey, fromValue, fn), MapType(toKey, toValue, tn)) 
=>
    +        resolve(fromKey, toKey) &&
    +          (!forceNullable(fromKey, toKey)) &&
    +          resolve(fromValue, toValue) &&
    +          resolvableNullability(fn || forceNullable(fromValue, toValue), 
tn)
    +
    +      case (StructType(fromFields), StructType(toFields)) =>
    +        fromFields.size == toFields.size &&
    +          fromFields.zip(toFields).forall {
    +            case (fromField, toField) =>
    +              resolve(fromField.dataType, toField.dataType) &&
    +                resolvableNullability(
    +                  fromField.nullable || forceNullable(fromField.dataType, 
toField.dataType),
    +                  toField.nullable)
    +          }
    +
    +      case _ => false
    --- End diff --
    
    I am wondering if throwing exception will be more informative, than plain 
`UnresolvedException` thrown in logical plan analyzing.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to