Skip to content

Commit b5399d4

Browse files
committed
[SPARK-33071][SPARK-33536][SQL][FOLLOW-UP] Rename deniedMetadataKeys to nonInheritableMetadataKeys in Alias
### What changes were proposed in this pull request? This PR is a followup of #30488. This PR proposes to rename `Alias.deniedMetadataKeys` to `Alias.nonInheritableMetadataKeys` to make it less confusing. ### Why are the changes needed? To make it easier to maintain and read. ### Does this PR introduce _any_ user-facing change? No. This is rather a code cleanup. ### How was this patch tested? Ran the unittests written in the previous PR manually. Jenkins and GitHub Actions in this PR should also test them. Closes #30682 from HyukjinKwon/SPARK-33071-SPARK-33536. Authored-by: HyukjinKwon <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
1 parent 9959d49 commit b5399d4

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ trait AliasHelper {
9090
exprId = a.exprId,
9191
qualifier = a.qualifier,
9292
explicitMetadata = Some(a.metadata),
93-
deniedMetadataKeys = a.deniedMetadataKeys)
93+
nonInheritableMetadataKeys = a.nonInheritableMetadataKeys)
9494
case a: MultiAlias =>
9595
a.copy(child = trimAliases(a.child))
9696
case other => trimAliases(other)

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,14 @@ abstract class Attribute extends LeafExpression with NamedExpression with NullIn
143143
* fully qualified way. Consider the examples tableName.name, subQueryAlias.name.
144144
* tableName and subQueryAlias are possible qualifiers.
145145
* @param explicitMetadata Explicit metadata associated with this alias that overwrites child's.
146-
* @param deniedMetadataKeys Keys of metadata entries that are supposed to be removed when
147-
* inheriting the metadata from the child.
146+
* @param nonInheritableMetadataKeys Keys of metadata entries that are supposed to be removed when
147+
* inheriting the metadata from the child.
148148
*/
149149
case class Alias(child: Expression, name: String)(
150150
val exprId: ExprId = NamedExpression.newExprId,
151151
val qualifier: Seq[String] = Seq.empty,
152152
val explicitMetadata: Option[Metadata] = None,
153-
val deniedMetadataKeys: Seq[String] = Seq.empty)
153+
val nonInheritableMetadataKeys: Seq[String] = Seq.empty)
154154
extends UnaryExpression with NamedExpression {
155155

156156
// Alias(Generator, xx) need to be transformed into Generate(generator, ...)
@@ -172,7 +172,7 @@ case class Alias(child: Expression, name: String)(
172172
child match {
173173
case named: NamedExpression =>
174174
val builder = new MetadataBuilder().withMetadata(named.metadata)
175-
deniedMetadataKeys.foreach(builder.remove)
175+
nonInheritableMetadataKeys.foreach(builder.remove)
176176
builder.build()
177177

178178
case _ => Metadata.empty
@@ -181,7 +181,10 @@ case class Alias(child: Expression, name: String)(
181181
}
182182

183183
def newInstance(): NamedExpression =
184-
Alias(child, name)(qualifier = qualifier, explicitMetadata = explicitMetadata)
184+
Alias(child, name)(
185+
qualifier = qualifier,
186+
explicitMetadata = explicitMetadata,
187+
nonInheritableMetadataKeys = nonInheritableMetadataKeys)
185188

186189
override def toAttribute: Attribute = {
187190
if (resolved) {
@@ -201,7 +204,7 @@ case class Alias(child: Expression, name: String)(
201204
override def toString: String = s"$child AS $name#${exprId.id}$typeSuffix$delaySuffix"
202205

203206
override protected final def otherCopyArgs: Seq[AnyRef] = {
204-
exprId :: qualifier :: explicitMetadata :: deniedMetadataKeys :: Nil
207+
exprId :: qualifier :: explicitMetadata :: nonInheritableMetadataKeys :: Nil
205208
}
206209

207210
override def hashCode(): Int = {
@@ -212,7 +215,8 @@ case class Alias(child: Expression, name: String)(
212215
override def equals(other: Any): Boolean = other match {
213216
case a: Alias =>
214217
name == a.name && exprId == a.exprId && child == a.child && qualifier == a.qualifier &&
215-
explicitMetadata == a.explicitMetadata && deniedMetadataKeys == a.deniedMetadataKeys
218+
explicitMetadata == a.explicitMetadata &&
219+
nonInheritableMetadataKeys == a.nonInheritableMetadataKeys
216220
case _ => false
217221
}
218222

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,10 +1164,11 @@ class Column(val expr: Expression) extends Logging {
11641164
* @since 2.0.0
11651165
*/
11661166
def name(alias: String): Column = withExpr {
1167-
// SPARK-33536: The Alias is no longer a column reference after converting to an attribute.
1168-
// These denied metadata keys are used to strip the column reference related metadata for
1169-
// the Alias. So it won't be caught as a column reference in DetectAmbiguousSelfJoin.
1170-
Alias(expr, alias)(deniedMetadataKeys = Seq(Dataset.DATASET_ID_KEY, Dataset.COL_POS_KEY))
1167+
// SPARK-33536: an alias is no longer a column reference. Therefore,
1168+
// we should not inherit the column reference related metadata in an alias
1169+
// so that it is not caught as a column reference in DetectAmbiguousSelfJoin.
1170+
Alias(expr, alias)(
1171+
nonInheritableMetadataKeys = Seq(Dataset.DATASET_ID_KEY, Dataset.COL_POS_KEY))
11711172
}
11721173

11731174
/**

sql/core/src/test/scala/org/apache/spark/sql/SparkSessionExtensionSuite.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,8 @@ class ColumnarAlias(child: ColumnarExpression, name: String)(
577577
override val exprId: ExprId = NamedExpression.newExprId,
578578
override val qualifier: Seq[String] = Seq.empty,
579579
override val explicitMetadata: Option[Metadata] = None,
580-
override val deniedMetadataKeys: Seq[String] = Seq.empty)
581-
extends Alias(child, name)(exprId, qualifier, explicitMetadata, deniedMetadataKeys)
580+
override val nonInheritableMetadataKeys: Seq[String] = Seq.empty)
581+
extends Alias(child, name)(exprId, qualifier, explicitMetadata, nonInheritableMetadataKeys)
582582
with ColumnarExpression {
583583

584584
override def columnarEval(batch: ColumnarBatch): Any = child.columnarEval(batch)
@@ -715,7 +715,7 @@ case class PreRuleReplaceAddWithBrokenVersion() extends Rule[SparkPlan] {
715715
def replaceWithColumnarExpression(exp: Expression): ColumnarExpression = exp match {
716716
case a: Alias =>
717717
new ColumnarAlias(replaceWithColumnarExpression(a.child),
718-
a.name)(a.exprId, a.qualifier, a.explicitMetadata, a.deniedMetadataKeys)
718+
a.name)(a.exprId, a.qualifier, a.explicitMetadata, a.nonInheritableMetadataKeys)
719719
case att: AttributeReference =>
720720
new ColumnarAttributeReference(att.name, att.dataType, att.nullable,
721721
att.metadata)(att.exprId, att.qualifier)

0 commit comments

Comments
 (0)