Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/12149#discussion_r58477013
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala 
---
    @@ -668,36 +650,22 @@ trait ScalaReflection {
       def schemaFor[T: TypeTag]: Schema = schemaFor(localTypeOf[T])
     
       /**
    -   * Return the Scala Type for `T` in the current classloader mirror.
    -   *
    -   * Use this method instead of the convenience method `universe.typeOf`, 
which
    -   * assumes that all types can be found in the classloader that loaded 
scala-reflect classes.
    -   * That's not necessarily the case when running using Eclipse launchers 
or even
    -   * Sbt console or test (without `fork := true`).
    -   *
    -   * @see SPARK-5281
    -   */
    -  // SPARK-13640: Synchronize this because TypeTag.tpe is not thread-safe 
in Scala 2.10.
    -  def localTypeOf[T: TypeTag]: `Type` = ScalaReflectionLock.synchronized {
    -    val tag = implicitly[TypeTag[T]]
    -    tag.in(mirror).tpe.normalize
    +    * Returns a catalyst DataType and its nullability for the given Scala 
Type using reflection.
    +    *
    +    * Unlike `schemaFor`, this method won't throw exception for 
un-supported type, it will return
    +    * `NullType` silently instead.
    +    */
    +  def silentSchemaFor(tpe: `Type`): Schema = try {
    +    schemaFor(tpe)
    +  } catch {
    +    case _: UnsupportedOperationException => Schema(NullType, nullable = 
true)
       }
     
       /** Returns a catalyst DataType and its nullability for the given Scala 
Type using reflection. */
       def schemaFor(tpe: `Type`): Schema = ScalaReflectionLock.synchronized {
    -    val className = getClassNameFromType(tpe)
    -
         tpe match {
    -
    -      case t if Utils.classIsLoadable(className) &&
    -        
Utils.classForName(className).isAnnotationPresent(classOf[SQLUserDefinedType]) 
=>
    -
    -        // Note: We check for classIsLoadable above since 
Utils.classForName uses Java reflection,
    -        //       whereas className is from Scala reflection.  This can 
make it hard to find classes
    -        //       in some cases, such as when a class is enclosed in an 
object (in which case
    -        //       Java appends a '$' to the object name but Scala does not).
    -        val udt = Utils.classForName(className)
    -          .getAnnotation(classOf[SQLUserDefinedType]).udt().newInstance()
    +      case t if t.typeSymbol.annotations exists (_.tpe =:= 
typeOf[SQLUserDefinedType]) =>
    --- End diff --
    
    nit: `annotations.exists(...`


---
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