Skip to content

Commit d2b373f

Browse files
committed
wenchen's comments
1 parent dfaa13b commit d2b373f

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)