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


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala:
##########
@@ -271,8 +271,9 @@ package object dsl {
       override def expr: Expression = Literal(s)
       def attr: UnresolvedAttribute = analysis.UnresolvedAttribute(s)
     }
-    implicit class DslAttr(attr: UnresolvedAttribute) extends 
ImplicitAttribute {
-      def s: String = attr.name
+    implicit class DslAttr(a: UnresolvedAttribute) extends ImplicitAttribute {
+      def s: String = a.name
+      override def attr: UnresolvedAttribute = a

Review Comment:
   let's fix this completely so that people won't step into this pitfall again.
   
   first problem:
   ```
   implicit class DslAttr(a: UnresolvedAttribute) ... {
     def s: String = a.name
   }
   abstract class ImplicitAttribute ... {
     def attr: UnresolvedAttribute = analysis.UnresolvedAttribute(s)
   }
   ```
   I think the real problem is `UnresolvedAttribute.name` can't be parsed back 
so this roundtrip is broken. We should update `def s` to
   ```
   def s: String = a.sql
   ```
   
   The second problem:
   ```
   implicit class DslAttr(a: UnresolvedAttribute) ... {
     def s: String = a.name
   }
   abstract class ImplicitAttribute ... {
     def int: AttributeReference = AttributeReference(s, IntegerType, nullable 
= true)()
   }
   ```
   The `s` is the qualified column name, and we should handle it properly when 
creating `AttributeReference`
   ```
   def int: AttributeReference = AttributeReference(attr.nameParts.head, 
IntegerType, nullable = true)(qualifier = attr.nameParts.init)
   ```



-- 
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