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
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private[sql] class CacheManager(sqlContext: SQLContext) extends Logging {
sqlContext.conf.useCompression,
sqlContext.conf.columnBatchSize,
storageLevel,
query.queryExecution.executedPlan,
sqlContext.executePlan(query.logicalPlan).executedPlan,
tableName))
}
}
Expand Down
26 changes: 26 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,32 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll with SQLTestUtils {
)
}

test("SPARK-7158 collect and take return different results") {
import java.util.UUID
import org.apache.spark.sql.types._

val df = Seq(Tuple1(1), Tuple1(2), Tuple1(3)).toDF("index")
// we except the id is materialized once
def id: () => String = () => { UUID.randomUUID().toString() }

val dfWithId = df.withColumn("id", callUDF(id, StringType))
// Make a new DataFrame (actually the same reference to the old one)
val cached = dfWithId.cache()
// Trigger the cache
val d0 = dfWithId.collect()
val d1 = cached.collect()
val d2 = cached.collect()

// Since the ID is only materialized once, then all of the records
// should come from the cache, not by re-computing. Otherwise, the ID
// will be different
assert(d0.map(_(0)) === d2.map(_(0)))
assert(d0.map(_(1)) === d2.map(_(1)))

assert(d1.map(_(0)) === d2.map(_(0)))
assert(d1.map(_(1)) === d2.map(_(1)))
}

test("grouping on nested fields") {
read.json(sparkContext.parallelize("""{"nested": {"attribute": 1}, "value": 2}""" :: Nil))
.registerTempTable("rows")
Expand Down