Skip to content
Snippets Groups Projects
Commit 03f3e91f authored by Yin Huai's avatar Yin Huai Committed by Davies Liu
Browse files

[SPARK-10422] [SQL] String column in InMemoryColumnarCache needs to override clone method

https://issues.apache.org/jira/browse/SPARK-10422

Author: Yin Huai <yhuai@databricks.com>

Closes #8578 from yhuai/SPARK-10422.
parent 6cd98c18
No related branches found
No related tags found
No related merge requests found
......@@ -339,6 +339,8 @@ private[sql] object STRING extends NativeColumnType(StringType, 7, 8) {
override def copyField(from: InternalRow, fromOrdinal: Int, to: MutableRow, toOrdinal: Int) {
setField(to, toOrdinal, getField(from, fromOrdinal))
}
override def clone(v: UTF8String): UTF8String = v.clone()
}
private[sql] object DATE extends NativeColumnType(DateType, 8, 4) {
......
......@@ -191,4 +191,24 @@ class InMemoryColumnarQuerySuite extends QueryTest with SharedSQLContext {
ctx.table("InMemoryCache_different_data_types").collect())
ctx.dropTempTable("InMemoryCache_different_data_types")
}
test("SPARK-10422: String column in InMemoryColumnarCache needs to override clone method") {
val df =
ctx.range(1, 100).selectExpr("id % 10 as id").rdd.map(id => Tuple1(s"str_$id")).toDF("i")
val cached = df.cache()
// count triggers the caching action. It should not throw.
cached.count()
// Make sure, the DataFrame is indeed cached.
assert(sqlContext.cacheManager.lookupCachedData(cached).nonEmpty)
// Check result.
checkAnswer(
cached,
ctx.range(1, 100).selectExpr("id % 10 as id").rdd.map(id => Tuple1(s"str_$id")).toDF("i")
)
// Drop the cache.
cached.unpersist()
}
}
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