HyukjinKwon commented on a change in pull request #28745:
URL: https://github.com/apache/spark/pull/28745#discussion_r436333468
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala
##########
@@ -23,14 +23,18 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.plans.logical.EventTimeWatermark
-import org.apache.spark.sql.catalyst.util.quoteIdentifier
+import org.apache.spark.sql.catalyst.util.{quoteIdentifier, toPrettySQL}
import org.apache.spark.sql.types._
object NamedExpression {
private val curId = new java.util.concurrent.atomic.AtomicLong()
private[expressions] val jvmId = UUID.randomUUID()
def newExprId: ExprId = ExprId(curId.getAndIncrement(), jvmId)
def unapply(expr: NamedExpression): Option[(String, DataType)] =
Some((expr.name, expr.dataType))
+ def fromExpression(expr: Expression): NamedExpression = expr match {
+ case ne: NamedExpression => ne
+ case _: Expression => Alias(expr, toPrettySQL(expr))()
+ }
Review comment:
I will send another PR to use this in other places, for example,
https://github.com/apache/spark/blob/a3a42b30d04009282e770c289b043ca5941e32e5/sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/AggUtils.scala#L147-L150
https://github.com/apache/spark/blob/6c80ebbccb7f354f645dd63a73114332d26f901f/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/dsl/package.scala#L361-L364
https://github.com/apache/spark/blob/17857f9b8bdf95eb64735eb986e86bf8fd8bc1a9/sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala#L83-L89
and possibly at:
https://github.com/apache/spark/blob/7195a18bf24d9506d2f8d9d4d93ff679b3d21b65/sql/core/src/main/scala/org/apache/spark/sql/Column.scala#L204
I can don't add this util here for now too if anyone is not sure on this.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]