Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/10943#discussion_r51608477
--- Diff: sql/core/src/main/scala/org/apache/spark/sql/DataFrame.scala ---
@@ -1255,9 +1240,9 @@ class DataFrame private[sql](
*/
@scala.annotation.varargs
def drop(colNames: String*): DataFrame = {
- val resolver = sqlContext.analyzer.resolver
- val remainingCols =
- schema.filter(f => colNames.forall(n => !resolver(f.name, n))).map(f
=> Column(f.name))
+ val output = queryExecution.analyzed.output
+ val droppedAttrs = colNames.map(n =>
resolveToIndex(n)).flatten.map(output)
+ val remainingCols =
output.filterNot(droppedAttrs.contains).map(Column(_))
--- End diff --
An easier approach is to use the indexes:
```
val indexesToDrop = colNames.map(indexOf).flatten
if (indexesToDrop.isEmpty) {
this
} else {
val output = queryExecution.analyzed.output
val remainingCols = (0 until output.length).diff(indexesToDrop).map(index
=> Column(output(index)))
select(remainingCols: _*)
}
```
---
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]