Skip to content

Commit

Permalink
[SPARK-2041][SQL] Correctly analyze queries where columnName == table…
Browse files Browse the repository at this point in the history
…Name.

Author: Michael Armbrust <michael@databricks.com>

Closes #985 from marmbrus/tableName and squashes the following commits:

3caaa27 [Michael Armbrust] Correctly analyze queries where columnName == tableName.

(cherry picked from commit c7a183b)
Signed-off-by: Reynold Xin <rxin@apache.org>
  • Loading branch information
marmbrus authored and rxin committed Jun 6, 2014
1 parent 70383b1 commit 4ac8135
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] {
// struct fields.
val options = children.flatMap(_.output).flatMap { option =>
// If the first part of the desired name matches a qualifier for this possible match, drop it.
val remainingParts = if (option.qualifiers contains parts.head) parts.drop(1) else parts
val remainingParts =
if (option.qualifiers.contains(parts.head) && parts.size > 1) parts.drop(1) else parts
if (option.name == remainingParts.head) (option, remainingParts.tail.toList) :: Nil else Nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class SQLQuerySuite extends QueryTest {
// Make sure the tables are loaded.
TestData

test("SPARK-2041 column name equals tablename") {
checkAnswer(
sql("SELECT tableName FROM tableName"),
"test")
}

test("index into array") {
checkAnswer(
sql("SELECT data, data[0], data[0] + data[1], data[0 + 1] FROM arrayData"),
Expand Down
3 changes: 3 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,7 @@ object TestData {
NullStrings(2, "ABC") ::
NullStrings(3, null) :: Nil)
nullStrings.registerAsTable("nullStrings")

case class TableName(tableName: String)
TestSQLContext.sparkContext.parallelize(TableName("test") :: Nil).registerAsTable("tableName")
}

0 comments on commit 4ac8135

Please sign in to comment.