aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst
diff options
context:
space:
mode:
authorReynold Xin <rxin@databricks.com>2016-07-05 11:36:05 -0700
committerReynold Xin <rxin@databricks.com>2016-07-05 11:36:05 -0700
commit16a2a7d714f945b06978e3bd20a58ea32f0621ac (patch)
tree76fd896b952ea96a890fcb5500af6344886c46cd /sql/catalyst
parent07d9c5327f050f9da611d5239f61ed73b36ce4e6 (diff)
downloadspark-16a2a7d714f945b06978e3bd20a58ea32f0621ac.tar.gz
spark-16a2a7d714f945b06978e3bd20a58ea32f0621ac.tar.bz2
spark-16a2a7d714f945b06978e3bd20a58ea32f0621ac.zip
[SPARK-16311][SQL] Metadata refresh should work on temporary views
## What changes were proposed in this pull request? This patch fixes the bug that the refresh command does not work on temporary views. This patch is based on https://github.com/apache/spark/pull/13989, but removes the public Dataset.refresh() API as well as improved test coverage. Note that I actually think the public refresh() API is very useful. We can in the future implement it by also invalidating the lazy vals in QueryExecution (or alternatively just create a new QueryExecution). ## How was this patch tested? Re-enabled a previously ignored test, and added a new test suite for Hive testing behavior of temporary views against MetastoreRelation. Author: Reynold Xin <rxin@databricks.com> Author: petermaxlee <petermaxlee@gmail.com> Closes #14009 from rxin/SPARK-16311.
Diffstat (limited to 'sql/catalyst')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala16
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala5
2 files changed, 13 insertions, 8 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
index 8c620d36e5..e1d49912c3 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
@@ -462,17 +462,17 @@ class SessionCatalog(
}
}
- // TODO: It's strange that we have both refresh and invalidate here.
-
/**
* Refresh the cache entry for a metastore table, if any.
*/
- def refreshTable(name: TableIdentifier): Unit = { /* no-op */ }
-
- /**
- * Invalidate the cache entry for a metastore table, if any.
- */
- def invalidateTable(name: TableIdentifier): Unit = { /* no-op */ }
+ def refreshTable(name: TableIdentifier): Unit = {
+ // Go through temporary tables and invalidate them.
+ // If the database is defined, this is definitely not a temp table.
+ // If the database is not defined, there is a good chance this is a temp table.
+ if (name.database.isEmpty) {
+ tempTables.get(name.table).foreach(_.refresh())
+ }
+ }
/**
* Drop all existing temporary tables.
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
index 4984f235b4..d0b2b5d7b2 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
@@ -265,6 +265,11 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
s"Reference '$name' is ambiguous, could be: $referenceNames.")
}
}
+
+ /**
+ * Refreshes (or invalidates) any metadata/data cached in the plan recursively.
+ */
+ def refresh(): Unit = children.foreach(_.refresh())
}
/**