Skip to content

Commit 511a731

Browse files
committed
[SPARK-2561][SQL] Fix apply schema
We need to use the analyzed attributes otherwise we end up with a tree that will never resolve. Author: Michael Armbrust <michael@databricks.com> Closes apache#1470 from marmbrus/fixApplySchema and squashes the following commits: f968195 [Michael Armbrust] Use analyzed attributes when applying the schema. 4969015 [Michael Armbrust] Add test case.
1 parent a4d6020 commit 511a731

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ class SchemaRDD(
430430
* @group schema
431431
*/
432432
private def applySchema(rdd: RDD[Row]): SchemaRDD = {
433-
new SchemaRDD(sqlContext, SparkLogicalPlan(ExistingRdd(logicalPlan.output, rdd)))
433+
new SchemaRDD(sqlContext, SparkLogicalPlan(ExistingRdd(queryExecution.analyzed.output, rdd)))
434434
}
435435

436436
// =======================================================================

sql/core/src/test/scala/org/apache/spark/sql/DslQuerySuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ class DslQuerySuite extends QueryTest {
3333
testData.collect().toSeq)
3434
}
3535

36+
test("repartition") {
37+
checkAnswer(
38+
testData.select('key).repartition(10).select('key),
39+
testData.select('key).collect().toSeq)
40+
}
41+
3642
test("agg") {
3743
checkAnswer(
3844
testData2.groupBy('a)('a, Sum('b)),

0 commit comments

Comments
 (0)