Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/14657#discussion_r75239485
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala
---
@@ -411,27 +411,29 @@ class SessionCatalog(
}
/**
- * Return a [[LogicalPlan]] that represents the given table.
+ * Return a [[LogicalPlan]] that represents the given table or view.
*
- * If a database is specified in `name`, this will return the table from
that database.
- * If no database is specified, this will first attempt to return a
temporary table with
- * the same name, then, if that does not exist, return the table from
the current database.
+ * If a database is specified in `name`, this will return the table/view
from that database.
+ * If no database is specified, this will first attempt to return a
temporary table/view with
+ * the same name, then, if that does not exist, return the table/view
from the current database.
+ *
+ * If the relation is a view, the relation will be wrapped in a
[[SubqueryAlias]] which will
+ * track the name of the view.
*/
def lookupRelation(name: TableIdentifier, alias: Option[String] = None):
LogicalPlan = {
synchronized {
val db = formatDatabaseName(name.database.getOrElse(currentDb))
val table = formatTableName(name.table)
- val relation =
- if (name.database.isDefined || !tempTables.contains(table)) {
- val metadata = externalCatalog.getTable(db, table)
- SimpleCatalogRelation(db, metadata)
- } else {
- tempTables(table)
+ val relationAlias = alias.getOrElse(table)
+ if (name.database.isDefined || !tempTables.contains(table)) {
+ val metadata = externalCatalog.getTable(db, table)
+ val view = Option(metadata.tableType).collect {
--- End diff --
we are too conservative here, `CatalogTable.tableType` should never be
null, and we use this assumption in a lot of places.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]