Skip to content

Commit 2991dd0

Browse files
seayimarmbrus
authored andcommitted
[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
1 parent d82e732 commit 2991dd0

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,15 @@ private[hive] case class MetastoreRelation
522522
}
523523
)
524524

525+
/** Only compare database and tablename, not alias. */
526+
override def sameResult(plan: LogicalPlan): Boolean = {
527+
plan match {
528+
case mr: MetastoreRelation =>
529+
mr.databaseName == databaseName && mr.tableName == tableName
530+
case _ => false
531+
}
532+
}
533+
525534
val tableDesc = HiveShim.getTableDesc(
526535
Class.forName(
527536
hiveQlTable.getSerializationLib,

sql/hive/src/test/scala/org/apache/spark/sql/hive/CachedTableSuite.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ class CachedTableSuite extends QueryTest {
6464
sql("SELECT * FROM src"),
6565
preCacheResults)
6666

67+
assertCached(sql("SELECT * FROM src s"))
68+
69+
checkAnswer(
70+
sql("SELECT * FROM src s"),
71+
preCacheResults)
72+
6773
uncacheTable("src")
6874
assertCached(sql("SELECT * FROM src"), 0)
6975
}

0 commit comments

Comments
 (0)