You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "cloud-fan (via GitHub)" <gi...@apache.org> on 2024/01/02 04:05:48 UTC

Re: [PR] [SPARK-46541][SQL][CONNECT] Fix the ambiguous column reference in self join [spark]

cloud-fan commented on code in PR #44532:
URL: https://github.com/apache/spark/pull/44532#discussion_r1439142630


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -520,9 +524,33 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
             "planId" -> planId.toString,
             "q" -> q.toString))
       }
-    })
 
-    val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).isDefined
+      val matched = found.flatMap { case (child, nodes) =>
+        val resolved = nodes
+          .flatMap(resolveUnresolvedAttributeByPlan(u, _, isMetadataAccess))
+        if (isMetadataAccess) {
+          // NOTE: A metadata column might appear in `output` instead of `metadataOutput`.
+          val metadataOutputSet = child.outputSet ++ AttributeSet(child.metadataOutput)
+          resolved.filter(metadataOutputSet.contains)
+        } else {
+          resolved.filter(child.outputSet.contains)
+        }
+      }
+      if (matched.length > 1) {
+        throw new AnalysisException(
+          errorClass = "AMBIGUOUS_COLUMN_REFERENCE",
+          messageParameters = Map("name" -> toSQLId(u.nameParts)),
+          origin = u.origin
+        )
+      }
+      matched.headOption
+    }
+  }
+
+  private def resolveUnresolvedAttributeByPlan(
+    u: UnresolvedAttribute,

Review Comment:
   nit: 4 spaces indentation



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org