Skip to content

Commit 3109d4f

Browse files
jerryshaopdeyhim
authored andcommitted
[SPARK-1354][SQL] Add tableName as a qualifier for SimpleCatelogy
Fix attribute unresolved when query with table name as a qualifier in SQLContext with SimplCatelog, details please see [SPARK-1354](https://issues.apache.org/jira/browse/SPARK-1354?jql=project%20%3D%20SPARK). Author: jerryshao <[email protected]> Closes apache#272 from jerryshao/qualifier-fix and squashes the following commits: 7950170 [jerryshao] Add tableName as a qualifier for SimpleCatelogy
1 parent 351605f commit 3109d4f

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Catalog.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ class SimpleCatalog extends Catalog {
4747
tableName: String,
4848
alias: Option[String] = None): LogicalPlan = {
4949
val table = tables.get(tableName).getOrElse(sys.error(s"Table Not Found: $tableName"))
50+
val tableWithQualifiers = Subquery(tableName, table)
5051

5152
// If an alias was specified by the lookup, wrap the plan in a subquery so that attributes are
5253
// properly qualified with this alias.
53-
alias.map(a => Subquery(a.toLowerCase, table)).getOrElse(table)
54+
alias.map(a => Subquery(a.toLowerCase, tableWithQualifiers)).getOrElse(tableWithQualifiers)
5455
}
5556
}
5657

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,31 @@ class SQLQuerySuite extends QueryTest {
216216
(null, null, 5, "E") ::
217217
(null, null, 6, "F") :: Nil)
218218
}
219+
220+
test("select with table name as qualifier") {
221+
checkAnswer(
222+
sql("SELECT testData.value FROM testData WHERE testData.key = 1"),
223+
Seq(Seq("1")))
224+
}
225+
226+
test("inner join ON with table name as qualifier") {
227+
checkAnswer(
228+
sql("SELECT * FROM upperCaseData JOIN lowerCaseData ON lowerCaseData.n = upperCaseData.N"),
229+
Seq(
230+
(1, "A", 1, "a"),
231+
(2, "B", 2, "b"),
232+
(3, "C", 3, "c"),
233+
(4, "D", 4, "d")))
234+
}
235+
236+
test("qualified select with inner join ON with table name as qualifier") {
237+
checkAnswer(
238+
sql("SELECT upperCaseData.N, upperCaseData.L FROM upperCaseData JOIN lowerCaseData " +
239+
"ON lowerCaseData.n = upperCaseData.N"),
240+
Seq(
241+
(1, "A"),
242+
(2, "B"),
243+
(3, "C"),
244+
(4, "D")))
245+
}
219246
}

0 commit comments

Comments
 (0)