Skip to content

Commit 387628f

Browse files
committed
cleanup
1 parent ff15c34 commit 387628f

3 files changed

Lines changed: 12 additions & 22 deletions

File tree

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/util/package.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ package org.apache.spark.sql.catalyst
2020
import java.io._
2121
import java.nio.charset.StandardCharsets
2222

23-
import org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute
2423
import org.apache.spark.sql.catalyst.expressions._
2524
import org.apache.spark.sql.types.{NumericType, StringType}
2625
import org.apache.spark.unsafe.types.UTF8String
@@ -138,10 +137,6 @@ package object util {
138137
// Replaces attributes, string literals, complex type extractors with their pretty form so that
139138
// generated column names don't contain back-ticks or double-quotes.
140139
def usePrettyExpression(e: Expression): Expression = e transform {
141-
// For unresolved attributes that generated by `DataFrame.col`, we should ignore the generated
142-
// qualifiers to not annoy users.
143-
case u: UnresolvedAttribute if u.nameParts(0).startsWith("dataframe_") =>
144-
new PrettyAttribute(u.copy(nameParts = u.nameParts.drop(1)))
145140
case a: Attribute => new PrettyAttribute(a)
146141
case Literal(s: UTF8String, StringType) => PrettyAttribute(s.toString, StringType)
147142
case Literal(v, t: NumericType) if v != null => PrettyAttribute(v.toString, t)

sql/core/src/main/scala/org/apache/spark/sql/Column.scala

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,6 @@ class Column(protected[sql] val expr: Expression) extends Logging {
118118
* Returns the expression for this column either with an existing or auto assigned name.
119119
*/
120120
private[sql] def named: NamedExpression = expr match {
121-
// Wrap UnresolvedAttribute with UnresolvedAlias, as when we resolve UnresolvedAttribute, we
122-
// will remove intermediate Alias for ExtractValue chain, and we need to alias it again to
123-
// make it a NamedExpression.
124-
case u: UnresolvedAttribute => UnresolvedAlias(u)
125-
126121
case u: UnresolvedExtractValue => UnresolvedAlias(u)
127122

128123
case expr: NamedExpression => expr
@@ -133,21 +128,28 @@ class Column(protected[sql] val expr: Expression) extends Logging {
133128

134129
case jt: JsonTuple => MultiAlias(jt, Nil)
135130

136-
case func: UnresolvedFunction => UnresolvedAlias(func, Some(usePrettyExpression(func).sql))
131+
case func: UnresolvedFunction => UnresolvedAlias(func, Some(toPresentableString(func)))
137132

138133
// If we have a top level Cast, there is a chance to give it a better alias, if there is a
139134
// NamedExpression under this Cast.
140135
case c: Cast => c.transformUp {
141136
case Cast(ne: NamedExpression, to) => UnresolvedAlias(Cast(ne, to))
142137
} match {
143138
case ne: NamedExpression => ne
144-
case other => Alias(expr, usePrettyExpression(expr).sql)()
139+
case other => Alias(expr, toPresentableString(expr))()
145140
}
146141

147-
case expr: Expression => Alias(expr, usePrettyExpression(expr).sql)()
142+
case expr: Expression => Alias(expr, toPresentableString(expr))()
148143
}
149144

150-
override def toString: String = usePrettyExpression(expr).sql
145+
override def toString: String = toPresentableString(expr)
146+
147+
private def toPresentableString(expr: Expression): String = usePrettyExpression(expr transform {
148+
// For unresolved attributes that generated by `DataFrame.col`, we should ignore the generated
149+
// qualifiers to not annoy users.
150+
case u: UnresolvedAttribute if u.nameParts(0).startsWith("dataframe_") =>
151+
u.copy(nameParts = u.nameParts.drop(1))
152+
}).sql
151153

152154
override def equals(that: Any): Boolean = that match {
153155
case that: Column => that.expr.equals(this.expr)

sql/core/src/main/scala/org/apache/spark/sql/RelationalGroupedDataset.scala

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,7 @@ class RelationalGroupedDataset protected[sql](
6767
}
6868
}
6969

70-
// Wrap UnresolvedAttribute with UnresolvedAlias, as when we resolve UnresolvedAttribute, we
71-
// will remove intermediate Alias for ExtractValue chain, and we need to alias it again to
72-
// make it a NamedExpression.
73-
private[this] def alias(expr: Expression): NamedExpression = expr match {
74-
case u: UnresolvedAttribute => UnresolvedAlias(u)
75-
case expr: NamedExpression => expr
76-
case expr: Expression => Alias(expr, usePrettyExpression(expr).sql)()
77-
}
70+
private[this] def alias(expr: Expression): NamedExpression = Column(expr).named
7871

7972
private[this] def aggregateNumericColumns(colNames: String*)(f: Expression => AggregateFunction)
8073
: DataFrame = {

0 commit comments

Comments
 (0)