Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/9089#discussion_r41833942
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
---
@@ -362,14 +362,35 @@ class Analyzer(
j
case Some((oldRelation, newRelation)) =>
val attributeRewrites =
AttributeMap(oldRelation.output.zip(newRelation.output))
- val newRight = right transformUp {
- case r if r == oldRelation => newRelation
- } transformUp {
- case other => other transformExpressions {
- case a: Attribute => attributeRewrites.get(a).getOrElse(a)
+ def applyRewrites(plan: LogicalPlan): LogicalPlan =
+ plan transformUp {
+ case r if r == oldRelation => newRelation
+ } transformUp {
+ case other => other transformExpressions {
+ case a: Attribute =>
attributeRewrites.get(a).getOrElse(a)
+ }
}
- }
- j.copy(right = newRight)
+ val newRight = applyRewrites(right)
+ // Also apply the rewrites to foreign keys on the left side,
because these are meant to
+ // reference the right side.
+ val newLeft =
+ if (left.keys.nonEmpty) {
+ left.transform {
+ case KeyHint(keys, child) =>
+ val newKeys = keys.collect {
+ case ForeignKey(attr, referencedRelation,
referencedAttr) =>
+ ForeignKey(
+ attr,
+ applyRewrites(referencedRelation),
+
attributeRewrites.get(referencedAttr).getOrElse(referencedAttr))
+ case other => other
+ }
+ KeyHint((keys ++ newKeys).distinct, child)
--- End diff --
Can't we just use `newKeys` here? Why do we need to keep old keys?
---
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]