Skip to content

Commit

Permalink
[SPARK-14004][SQL][MINOR] AttributeReference and Alias should only us…
Browse files Browse the repository at this point in the history
…e the first qualifier to generate SQL strings

## What changes were proposed in this pull request?

Current implementations of `AttributeReference.sql` and `Alias.sql` joins all available qualifiers, which is logically wrong. But this implementation mistake doesn't cause any real SQL generation bugs though, since there is always at most one qualifier for any given `AttributeReference` or `Alias`.

This PR fixes this issue by only picking the first qualifiers.

## How was this patch tested?

(Please explain how this patch was tested. E.g. unit tests, integration tests, manual tests)

Existing tests should be enough.

Author: Cheng Lian <lian@databricks.com>

Closes apache#11820 from liancheng/spark-14004-single-qualifier.
  • Loading branch information
liancheng authored and roygao94 committed Mar 22, 2016
1 parent 8a1cf25 commit c255d7f
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ case class Alias(child: Expression, name: String)(
}

override def sql: String = {
val qualifiersString =
if (qualifiers.isEmpty) "" else qualifiers.map(quoteIdentifier).mkString("", ".", ".")
val qualifiersString = if (qualifiers.isEmpty) "" else qualifiers.head + "."
s"${child.sql} AS $qualifiersString${quoteIdentifier(name)}"
}
}
Expand Down Expand Up @@ -299,8 +298,7 @@ case class AttributeReference(
override def simpleString: String = s"$name#${exprId.id}: ${dataType.simpleString}"

override def sql: String = {
val qualifiersString =
if (qualifiers.isEmpty) "" else qualifiers.map(quoteIdentifier).mkString("", ".", ".")
val qualifiersString = if (qualifiers.isEmpty) "" else qualifiers.head + "."
s"$qualifiersString${quoteIdentifier(name)}"
}
}
Expand Down

0 comments on commit c255d7f

Please sign in to comment.