Skip to content

Commit 611d3c2

Browse files
committed
move metadata from Expr to NamedExpr
1 parent ddfcfad commit 611d3c2

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ abstract class Expression extends TreeNode[Expression] {
4444
def nullable: Boolean
4545
def references: AttributeSet = AttributeSet(children.flatMap(_.references.iterator))
4646

47-
/** Returns the metadata when an expression is a reference to another expression with metadata. */
48-
def metadata: Metadata = Metadata.empty
49-
5047
/** Returns the result of evaluating this expression on a given input Row */
5148
def eval(input: Row = null): EvaluatedType
5249

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ abstract class NamedExpression extends Expression {
4444

4545
def toAttribute: Attribute
4646

47+
/** Returns the metadata when an expression is a reference to another expression with metadata. */
48+
def metadata: Metadata = Metadata.empty
49+
4750
protected def typeSuffix =
4851
if (resolved) {
4952
dataType match {
@@ -89,11 +92,16 @@ case class Alias(child: Expression, name: String)
8992

9093
override def dataType = child.dataType
9194
override def nullable = child.nullable
92-
override def metadata: Metadata = child.metadata
95+
override def metadata: Metadata = {
96+
child match {
97+
case named: NamedExpression => named.metadata
98+
case _ => Metadata.empty
99+
}
100+
}
93101

94102
override def toAttribute = {
95103
if (resolved) {
96-
AttributeReference(name, child.dataType, child.nullable, child.metadata)(exprId, qualifiers)
104+
AttributeReference(name, child.dataType, child.nullable, metadata)(exprId, qualifiers)
97105
} else {
98106
UnresolvedAttribute(name)
99107
}

0 commit comments

Comments
 (0)