diff options
author | Cheng Lian <lian@databricks.com> | 2016-03-19 00:22:17 +0800 |
---|---|---|
committer | Cheng Lian <lian@databricks.com> | 2016-03-19 00:22:17 +0800 |
commit | 14c7236dc63fe362f052175886e9ad700419bc63 (patch) | |
tree | b20b3176a0222995d392f60edce3c76c8e4abd3c /sql/catalyst | |
parent | 0acb32a3f19484d3ea3b60fccef596025c8a8f83 (diff) | |
download | spark-14c7236dc63fe362f052175886e9ad700419bc63.tar.gz spark-14c7236dc63fe362f052175886e9ad700419bc63.tar.bz2 spark-14c7236dc63fe362f052175886e9ad700419bc63.zip |
[SPARK-14004][SQL][MINOR] AttributeReference and Alias should only use 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 #11820 from liancheng/spark-14004-single-qualifier.
Diffstat (limited to 'sql/catalyst')
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala index 271ef33090..8c63cce82a 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/namedExpressions.scala @@ -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)}" } } @@ -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)}" } } |