Skip to content

Commit c40895f

Browse files
committed
address PR comments
1 parent 24daf5f commit c40895f

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,11 @@ package object expressions {
153153
}
154154

155155
/** Returns true if all qualifiers in `attrs` have 2 or less parts. */
156-
@transient private val hasTwoOrLessPartQualifiers: Boolean =
156+
@transient private val hasTwoOrLessQualifierParts: Boolean =
157157
attrs.forall(_.qualifier.length <= 2)
158158

159159
/** Match attributes for the case where all qualifiers in `attrs` have 2 or less parts. */
160-
private def matchWithTwoOrLessPartQualifiers(
160+
private def matchWithTwoOrLessQualifierParts(
161161
nameParts: Seq[String],
162162
resolver: Resolver): (Seq[Attribute], Seq[String]) = {
163163
// Collect matching attributes given a name and a lookup.
@@ -221,7 +221,7 @@ package object expressions {
221221
/**
222222
* Match attributes for the case where at least one qualifier in `attrs` has more than 2 parts.
223223
*/
224-
private def matchWithThreeOrMorePartQualifiers(
224+
private def matchWithThreeOrMoreQualifierParts(
225225
nameParts: Seq[String],
226226
resolver: Resolver): (Seq[Attribute], Seq[String]) = {
227227
// Returns true if the `short` qualifier is a subset of the last elements of
@@ -277,10 +277,10 @@ package object expressions {
277277

278278
/** Perform attribute resolution given a name and a resolver. */
279279
def resolve(nameParts: Seq[String], resolver: Resolver): Option[NamedExpression] = {
280-
val (candidates, nestedFields) = if (hasTwoOrLessPartQualifiers) {
281-
matchWithTwoOrLessPartQualifiers(nameParts, resolver)
280+
val (candidates, nestedFields) = if (hasTwoOrLessQualifierParts) {
281+
matchWithTwoOrLessQualifierParts(nameParts, resolver)
282282
} else {
283-
matchWithThreeOrMorePartQualifiers(nameParts, resolver)
283+
matchWithThreeOrMoreQualifierParts(nameParts, resolver)
284284
}
285285

286286
def name = UnresolvedAttribute(nameParts).name

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/AttributeResolutionSuite.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,28 @@ class AttributeResolutionSuite extends SparkFunSuite {
3838
}
3939
}
4040

41-
// Non-matching cases.
41+
// Non-matching cases
4242
Seq(Seq("ns1", "ns2", "t1"), Seq("ns2", "a")).foreach { nameParts =>
43-
val resolved = attrs.resolve(nameParts, resolver)
44-
assert(resolved.isEmpty)
43+
assert(attrs.resolve(nameParts, resolver).isEmpty)
4544
}
4645
}
4746

47+
test("attribute resolution where table and attribute names are the same") {
48+
val attrs = Seq(AttributeReference("t", IntegerType)(qualifier = Seq("ns1", "ns2", "t")))
49+
// Matching cases
50+
Seq(
51+
Seq("t"), Seq("t", "t"), Seq("ns2", "t", "t"), Seq("ns1", "ns2", "t", "t")
52+
).foreach { nameParts =>
53+
attrs.resolve(nameParts, resolver) match {
54+
case Some(attr) => assert(attr.semanticEquals(attrs(0)))
55+
case _ => fail()
56+
}
57+
}
58+
59+
// Non-matching case
60+
assert(attrs.resolve(Seq("ns1", "ns2", "t"), resolver).isEmpty)
61+
}
62+
4863
test("attribute resolution ambiguity at the attribute name level") {
4964
val attrs = Seq(
5065
AttributeReference("a", IntegerType)(qualifier = Seq("ns1", "t1")),

0 commit comments

Comments
 (0)