mickjermsurawong-stripe commented on a change in pull request #25736: 
[SPARK-29026][SQL] Improve error message in `schemaFor` in trait without 
companion object constructor
URL: https://github.com/apache/spark/pull/25736#discussion_r322544479
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/ScalaReflection.scala
 ##########
 @@ -906,7 +906,19 @@ trait ScalaReflection extends Logging {
    * only defines a constructor via `apply` method.
    */
   private def getCompanionConstructor(tpe: Type): Symbol = {
-    
tpe.typeSymbol.asClass.companion.asTerm.typeSignature.member(universe.TermName("apply"))
+    def throwUnsupportedOperation = {
+      throw new UnsupportedOperationException(s"Unable to find constructor for 
$tpe. " +
+        s"This could happen if $tpe is an interface, or a trait without 
companion object " +
+        "constructor.")
+    }
+    val companionSym = tpe.typeSymbol.asClass.companion match {
+      case NoSymbol => throwUnsupportedOperation
+      case sym => sym
+    }
 
 Review comment:
   Updated to nested patter match, but retained the inner method to throw 
exception

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to