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

    https://github.com/apache/spark/pull/10943#discussion_r51355492
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala ---
    @@ -150,6 +153,17 @@ class DataFrame private[sql](
         }
       }
     
    +  /**
    +   * Resolves a column name. This is called when it is required to resolve 
a column by its
    +   * name only and not as a column path..
    +   */
    +  private[sql] def resolveColName(colName: String, userSuppliedName: 
String): Boolean = {
    --- End diff --
    
    how about
    ```
    private[sql] def indexOf(colName: String): Option[Int] = {
      val resolver = sqlContext.analyzer.resolver
      val index = queryExecution.analyzed.output.indexWhere(f => 
resolver(f.name, colName))
      if (index >= 0) Some(index) else None
    }
    ```
    
    then we can rewrite `withColumn` to:
    ```
    indexOf(colName).map { index =>
      select(output.updated(index, col.as(colName)).map(Column(_)) : _*)
    }.getOrElse {
      select(Column("*"), col.as(colName))
    }
    ```
    
    There may be better name for this, like `resolveToIndex`


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