Skip to content

Commit

Permalink
sql (fix): ResolvedIdentifier can wrongly have a qualifier (#3142)
Browse files Browse the repository at this point in the history
  • Loading branch information
takezoe authored Aug 17, 2023
1 parent 016f929 commit 42862fb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ object TypeResolver extends LogSupport {

val results = expr match {
case i: Identifier =>
lookup(i.value, context).map(toResolvedAttribute(i.value, _))
lookup(i.value, context).map(toResolvedAttribute(i.value, _).withQualifier(None))
case u @ UnresolvedAttribute(qualifier, name, _, _) =>
lookup(u.fullName, context).map(toResolvedAttribute(name, _).withQualifier(qualifier))
case a @ AllColumns(qualifier, None, _, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,4 +1138,15 @@ class TypeResolverTest extends AirSpec with ResolverTestHelper {
col.sourceColumn.head.fullName shouldBe "A.id"
}
}

test("Resolve identifier refers to column alias for qualified column") {
val p1 = analyze("select count(xid) from (select n1.id as xid from A n1 inner join B on n1.id = B.id)")
p1.outputAttributes shouldMatch { case List(SingleColumn(f: FunctionCall, None, None, _)) =>
f.functionName shouldBe "count"
f.args shouldMatch { case Seq(col: ResolvedAttribute) =>
col.fullName shouldBe "xid"
col.sourceColumn.map(_.column) shouldBe Some(a1)
}
}
}
}

0 comments on commit 42862fb

Please sign in to comment.