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

    https://github.com/apache/spark/pull/6585#discussion_r31684387
  
    --- Diff: sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala 
---
    @@ -334,6 +334,50 @@ class DataFrameSuite extends QueryTest {
         assert(df.schema.map(_.name) === Seq("key", "value"))
       }
     
    +  test("drop column using drop with column reference") {
    +    val col = testData("key")
    +    val df = testData.drop(col)
    +    checkAnswer(
    +      df,
    +      testData.collect().map(x => Row(x.getString(1))).toSeq)
    +    assert(df.schema.map(_.name) === Seq("value"))
    +  }
    +
    +  test("drop unknown column (no-op) with column reference") {
    +    val col = Column("random")
    +    val df = testData.drop(col)
    +    checkAnswer(
    +      df,
    +      testData.collect().toSeq)
    +    assert(df.schema.map(_.name) === Seq("key", "value"))
    +  }
    +
    +  test("drop unknown column with same name (no-op) with column reference") 
{
    +    val col = Column("key")
    +    val df = testData.drop(col)
    +    checkAnswer(
    +      df,
    +      testData.collect().toSeq)
    +    assert(df.schema.map(_.name) === Seq("key", "value"))
    +  }
    +
    +  test("drop column after join with duplicate columns using column 
reference") {
    +    val newSalary = salary.withColumnRenamed("personId", "id")
    +    val col = newSalary("id")
    +    // this join will result in duplicate "id" columns
    +    val joinedDf = person.join(newSalary,
    +      person("id") === newSalary("id"), "inner")
    +    // remove only the "id" column that was associated with newSalary
    +    val df = joinedDf.drop(col)
    +    checkAnswer(
    +      df,
    +      joinedDf.collect().map { case Row(id: Int, name: String, age: Int,
    +                                        idToDrop: Int, salary: Double) =>
    +        Row(id, name, age, salary)
    +      }.toSeq)
    +    assert(df.schema.map(_.name) === Seq("id", "name", "age", "salary"))
    --- End diff --
    
    Maybe we should add `asset(df("id") == person("id"))`


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