ueshin commented on code in PR #48820:
URL: https://github.com/apache/spark/pull/48820#discussion_r1838571341


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala:
##########
@@ -1004,42 +1004,29 @@ case class UnresolvedTranspose(
     copy(child = newChild)
 }
 
-case class UnresolvedOuterReference(
-    nameParts: Seq[String])
+case class UnresolvedOuterReference(nameParts: Seq[String])
   extends LeafExpression with NamedExpression with Unevaluable {
-
-  def name: String =
-    nameParts.map(n => if (n.contains(".")) s"`$n`" else n).mkString(".")
-
+  def name: String = nameParts.map(quoteIfNeeded).mkString(".")

Review Comment:
   👍 



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala:
##########
@@ -69,7 +68,10 @@ class QueryExecution(
   // TODO: Move the planner an optimizer into here from SessionState.
   protected def planner = sparkSession.sessionState.planner
 
-  lazy val isLazyAnalysis: Boolean = 
logical.containsAnyPattern(LAZY_ANALYSIS_EXPRESSION)
+  lazy val isLazyAnalysis: Boolean = {
+    // Only check the main query as we can resolve LazyOuterReference inside 
subquery expressions.
+    
logical.exists(_.expressions.exists(_.exists(_.isInstanceOf[LazyOuterReference])))

Review Comment:
   oh, `logical.containsAnyPattern(LAZY_ANALYSIS_EXPRESSION)` will check 
subqueries?
   I also intended to check the main query. Thanks for the correction!



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/unresolved.scala:
##########
@@ -1004,42 +1004,29 @@ case class UnresolvedTranspose(
     copy(child = newChild)
 }
 
-case class UnresolvedOuterReference(
-    nameParts: Seq[String])
+case class UnresolvedOuterReference(nameParts: Seq[String])
   extends LeafExpression with NamedExpression with Unevaluable {
-
-  def name: String =
-    nameParts.map(n => if (n.contains(".")) s"`$n`" else n).mkString(".")
-
+  def name: String = nameParts.map(quoteIfNeeded).mkString(".")
   override def exprId: ExprId = throw new UnresolvedException("exprId")
   override def dataType: DataType = throw new UnresolvedException("dataType")
   override def nullable: Boolean = throw new UnresolvedException("nullable")
   override def qualifier: Seq[String] = throw new 
UnresolvedException("qualifier")
   override lazy val resolved = false
-
   override def toAttribute: Attribute = throw new 
UnresolvedException("toAttribute")
   override def newInstance(): UnresolvedOuterReference = this
-
   final override val nodePatterns: Seq[TreePattern] = 
Seq(UNRESOLVED_OUTER_REFERENCE)
 }
 
-case class LazyOuterReference(
-     nameParts: Seq[String])
+case class LazyOuterReference(nameParts: Seq[String])
   extends LeafExpression with NamedExpression with Unevaluable with 
LazyAnalysisExpression {
-
-  def name: String =
-    nameParts.map(n => if (n.contains(".")) s"`$n`" else n).mkString(".")
-
+  def name: String = nameParts.map(quoteIfNeeded).mkString(".")

Review Comment:
   👍 



##########
sql/core/src/main/scala/org/apache/spark/sql/execution/QueryExecution.scala:
##########
@@ -69,7 +68,10 @@ class QueryExecution(
   // TODO: Move the planner an optimizer into here from SessionState.
   protected def planner = sparkSession.sessionState.planner
 
-  lazy val isLazyAnalysis: Boolean = 
logical.containsAnyPattern(LAZY_ANALYSIS_EXPRESSION)
+  lazy val isLazyAnalysis: Boolean = {
+    // Only check the main query as we can resolve LazyOuterReference inside 
subquery expressions.
+    
logical.exists(_.expressions.exists(_.exists(_.isInstanceOf[LazyOuterReference])))

Review Comment:
   nit: it should be `LazyAnalysisExpression`, although currently only 
`LazyOuterReference`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to