Github user yhuai commented on a diff in the pull request:
https://github.com/apache/spark/pull/16233#discussion_r93898018
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -510,32 +510,94 @@ class Analyzer(
* Replaces [[UnresolvedRelation]]s with concrete relations from the
catalog.
*/
object ResolveRelations extends Rule[LogicalPlan] {
- private def lookupTableFromCatalog(u: UnresolvedRelation): LogicalPlan
= {
+
+ def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators {
+ case i @ InsertIntoTable(u: UnresolvedRelation, parts, child, _, _)
if child.resolved =>
+ i.copy(table = EliminateSubqueryAliases(lookupTableFromCatalog(u)))
+ case u: UnresolvedRelation => resolveRelation(u)
+ }
+
+ // If the unresolved relation is running directly on files, we just
return the original
+ // UnresolvedRelation, the plan will get resolved later. Else we look
up the table from catalog
+ // and change the default database name if it is a view.
+ //
+ // Note this is compatible with the views defined by older versions of
Spark(before 2.2), which
+ // have empty defaultDatabase and all the relations in viewText have
database part defined.
+ def resolveRelation(
+ plan: LogicalPlan,
+ defaultDatabase: Option[String] = None): LogicalPlan = plan match {
--- End diff --
Let's explain defaultDatabase more, like when we need it, when it is set,
and how it is different from the current database in the session catalog.
---
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]