spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hvanhovell <...@git.apache.org>
Subject [GitHub] spark pull request #20757: [SPARK-23595][SQL] ValidateExternalType should su...
Date Wed, 07 Mar 2018 09:44:48 GMT
Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/20757#discussion_r172787179
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/objects/objects.scala
---
    @@ -1408,11 +1409,37 @@ case class ValidateExternalType(child: Expression, expected: DataType)
     
       override def dataType: DataType = RowEncoder.externalDataTypeForInput(expected)
     
    -  override def eval(input: InternalRow): Any =
    -    throw new UnsupportedOperationException("Only code-generated evaluation is supported")
    -
       private val errMsg = s" is not a valid external type for schema of ${expected.simpleString}"
     
    +  private lazy val checkType = expected match {
    +    case _: DecimalType =>
    +      (value: Any) => {
    +        Seq(classOf[java.math.BigDecimal], classOf[scala.math.BigDecimal], classOf[Decimal])
    +          .exists { x => value.getClass.isAssignableFrom(x) }
    +      }
    +    case _: ArrayType =>
    +      (value: Any) => {
    +        value.getClass.isAssignableFrom(classOf[Seq[_]]) || value.getClass.isArray
    +      }
    +    case _ if ScalaReflection.isNativeType(expected) =>
    +      (value: Any) => {
    +        value.getClass.isAssignableFrom(ScalaReflection.classForNativeTypeOf(expected))
    --- End diff --
    
    It might also be a bit faster if we use `isInstance` here. All of these classes do not
have subclasses.


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message