Skip to content
Snippets Groups Projects
Commit 052dee07 authored by Michael Armbrust's avatar Michael Armbrust
Browse files

[SPARK-6686][SQL] Use resolved output instead of names for toDF rename

This is a workaround for a problem reported on the user list.  This doesn't fix the core problem, but in general is a more robust way to do renames.

Author: Michael Armbrust <michael@databricks.com>

Closes #5337 from marmbrus/toDFrename and squashes the following commits:

6a3159d [Michael Armbrust] [SPARK-6686][SQL] Use resolved output instead of names for toDF rename
parent 947802cb
No related branches found
No related tags found
No related merge requests found
......@@ -240,8 +240,8 @@ class DataFrame private[sql](
s"Old column names (${schema.size}): " + schema.fields.map(_.name).mkString(", ") + "\n" +
s"New column names (${colNames.size}): " + colNames.mkString(", "))
val newCols = schema.fieldNames.zip(colNames).map { case (oldName, newName) =>
apply(oldName).as(newName)
val newCols = logicalPlan.output.zip(colNames).map { case (oldAttribute, newName) =>
Column(oldAttribute).as(newName)
}
select(newCols :_*)
}
......
......@@ -60,6 +60,14 @@ class DataFrameSuite extends QueryTest {
assert($"test".toString === "test")
}
test("rename nested groupby") {
val df = Seq((1,(1,1))).toDF()
checkAnswer(
df.groupBy("_1").agg(col("_1"), sum("_2._1")).toDF("key", "total"),
Row(1, 1) :: Nil)
}
test("invalid plan toString, debug mode") {
val oldSetting = TestSQLContext.conf.dataFrameEagerAnalysis
TestSQLContext.setConf(SQLConf.DATAFRAME_EAGER_ANALYSIS, "true")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment