Github user marmbrus commented on the pull request:

    https://github.com/apache/spark/pull/10311#issuecomment-164846751
  
    Scala always puts the parameter names in the `scalasig` and you can get 
them from the `Type` (which they describe how to get 
[here](http://stackoverflow.com/questions/16724588/is-it-possible-to-get-the-typetag-of-a-runtime-instance))
    
    ```scala
      def parameterNames: Seq[String] = {
        import scala.reflect.runtime.universe._
        val m = runtimeMirror(this.getClass.getClassLoader)
        val classSymbol = m.staticClass(this.getClass.getName)
        val t = classSymbol.selfType
        val formalTypeArgs = t.typeSymbol.asClass.typeParams
        val TypeRef(_, _, actualTypeArgs) = t
        val constructorSymbol = t.member(nme.CONSTRUCTOR)
        val params = if (constructorSymbol.isMethod) {
          constructorSymbol.asMethod.paramss
        } else {
          // Find the primary constructor, and use its parameter ordering.
          val primaryConstructorSymbol: Option[Symbol] = 
constructorSymbol.asTerm.alternatives.find(
            s => s.isMethod && s.asMethod.isPrimaryConstructor)
          if (primaryConstructorSymbol.isEmpty) {
            sys.error("Internal SQL error: Product object did not have a 
primary constructor.")
          } else {
            primaryConstructorSymbol.get.asMethod.paramss
          }
        }
    
        params.head.map(_.name.toString)
      }
    ```
    
    ```scala
    scala> sql("SELECT 1").queryExecution.logical.parameterNames
    res1: Seq[String] = List(projectList, child)
    ```
    
    Note thats just a quick draft and you could probably simplify it (or pull 
this out into a utility since I think we do it in several places now).


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