Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sql/core/src/main/scala/org/apache/spark/sql/SchemaRDD.scala
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ class SchemaRDD(
*/
private def applySchema(rdd: RDD[Row]): SchemaRDD = {
new SchemaRDD(sqlContext,
SparkLogicalPlan(ExistingRdd(queryExecution.analyzed.output, rdd))(sqlContext))
SparkLogicalPlan(
ExistingRdd(queryExecution.analyzed.output.map(_.newInstance), rdd))(sqlContext))
}

// =======================================================================
Expand Down
14 changes: 14 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/DslQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.apache.spark.sql

import org.apache.spark.sql.catalyst.analysis._
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans._
import org.apache.spark.sql.test._

/* Implicits */
Expand Down Expand Up @@ -133,6 +135,18 @@ class DslQuerySuite extends QueryTest {
mapData.take(1).toSeq)
}

test("SPARK-3395 limit distinct") {
val filtered = TestData.testData2
.distinct()
.orderBy(SortOrder('a, Ascending), SortOrder('b, Ascending))
.limit(1)
.registerTempTable("onerow")
checkAnswer(
sql("select * from onerow inner join testData2 on onerow.a = testData2.a"),
(1, 1, 1, 1) ::
(1, 1, 1, 2) :: Nil)
}

test("average") {
checkAnswer(
testData2.groupBy()(avg('a)),
Expand Down