File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
sql/core/src/main/scala/org/apache/spark/sql Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -1215,8 +1215,8 @@ class DataFrame private[sql](
12151215 def withColumnRenamed (existingName : String , newName : String ): DataFrame = {
12161216 val output = queryExecution.analyzed.output
12171217 resolveToIndex(existingName).map {index =>
1218- select (output.map(attr =>
1219- Column (attr)).updated(index, Column (output(index)).as(newName) ) : _* )
1218+ val renamed = Column (output(index)).as(newName)
1219+ select(output.map(attr => Column (attr)).updated(index, renamed ) : _* )
12201220 }.getOrElse {
12211221 this
12221222 }
@@ -1240,13 +1240,13 @@ class DataFrame private[sql](
12401240 */
12411241 @ scala.annotation.varargs
12421242 def drop (colNames : String * ): DataFrame = {
1243- val output = queryExecution.analyzed.output
1244- val droppedAttrs = colNames.map(n => resolveToIndex(n)).flatten.map(output)
1245- val remainingCols = output.filterNot(droppedAttrs.contains).map(Column (_))
1246- if (remainingCols.size == this .schema.size) {
1243+ val indexesToDrop = colNames.flatMap(resolveToIndex)
1244+ if (indexesToDrop.isEmpty) {
12471245 this
12481246 } else {
1249- this .select(remainingCols : _* )
1247+ val output = queryExecution.analyzed.output
1248+ val remainingCols = output.indices.diff(indexesToDrop).map(index => Column (output(index)))
1249+ select(remainingCols : _* )
12501250 }
12511251 }
12521252
You can’t perform that action at this time.
0 commit comments