aboutsummaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorseayi <405078363@qq.com>2015-02-02 16:06:52 -0800
committerMichael Armbrust <michael@databricks.com>2015-02-02 16:18:55 -0800
commitdca6faa29a8dd805cf364ed2683efaf7928f2112 (patch)
treef0dea0e0195bb2b29a1ef6c34bab752290b2107b /sql
parentb1aa8fe988301b924048039529234278aeb0298a (diff)
downloadspark-dca6faa29a8dd805cf364ed2683efaf7928f2112.tar.gz
spark-dca6faa29a8dd805cf364ed2683efaf7928f2112.tar.bz2
spark-dca6faa29a8dd805cf364ed2683efaf7928f2112.zip
[SPARK-5195][sql]Update HiveMetastoreCatalog.scala(override the MetastoreRelation's sameresult method only compare databasename and table name)
override the MetastoreRelation's sameresult method only compare databasename and table name because in previous : cache table t1; select count(*) from t1; it will read data from memory but the sql below will not,instead it read from hdfs: select count(*) from t1 t; because cache data is keyed by logical plan and compare with sameResult ,so when table with alias the same table 's logicalplan is not the same logical plan with out alias so modify the sameresult method only compare databasename and table name Author: seayi <405078363@qq.com> Author: Michael Armbrust <michael@databricks.com> Closes #3898 from seayi/branch-1.2 and squashes the following commits: 8f0c7d2 [seayi] Update CachedTableSuite.scala a277120 [seayi] Update HiveMetastoreCatalog.scala 8d910aa [seayi] Update HiveMetastoreCatalog.scala
Diffstat (limited to 'sql')
-rw-r--r--sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala9
-rw-r--r--sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala6
2 files changed, 15 insertions, 0 deletions
diff --git a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
index 1a49f09bd9..d910ee9509 100644
--- a/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
+++ b/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala
@@ -519,6 +519,15 @@ private[hive] case class MetastoreRelation
}
)
+ /** Only compare database and tablename, not alias. */
+ override def sameResult(plan: LogicalPlan): Boolean = {
+ plan match {
+ case mr: MetastoreRelation =>
+ mr.databaseName == databaseName && mr.tableName == tableName
+ case _ => false
+ }
+ }
+
val tableDesc = HiveShim.getTableDesc(
Class.forName(
hiveQlTable.getSerializationLib,
diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala
index 61e5117fea..7c8b5205e2 100644
--- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala
+++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala
@@ -64,6 +64,12 @@ class CachedTableSuite extends QueryTest {
sql("SELECT * FROM src"),
preCacheResults)
+ assertCached(sql("SELECT * FROM src s"))
+
+ checkAnswer(
+ sql("SELECT * FROM src s"),
+ preCacheResults)
+
uncacheTable("src")
assertCached(sql("SELECT * FROM src"), 0)
}