diff options
author | Wenchen Fan <cloud0fan@outlook.com> | 2015-07-01 10:31:35 -0700 |
---|---|---|
committer | Reynold Xin <rxin@databricks.com> | 2015-07-01 10:31:49 -0700 |
commit | 2f85d8ee0c8106c99b9994bf0de2b86233c3f4b4 (patch) | |
tree | 45a84c92af3d128ae1823333e668d8ddc7009a55 | |
parent | 214550b83f31837c6122636c0c84f77d3bb87273 (diff) | |
download | spark-2f85d8ee0c8106c99b9994bf0de2b86233c3f4b4.tar.gz spark-2f85d8ee0c8106c99b9994bf0de2b86233c3f4b4.tar.bz2 spark-2f85d8ee0c8106c99b9994bf0de2b86233c3f4b4.zip |
[SPARK-8621] [SQL] support empty string as column name
improve the empty check in `parseAttributeName` so that we can allow empty string as column name.
Close https://github.com/apache/spark/pull/7117
Author: Wenchen Fan <cloud0fan@outlook.com>
Closes #7149 from cloud-fan/8621 and squashes the following commits:
efa9e3e [Wenchen Fan] support empty string
(cherry picked from commit 31b4a3d7f2be9053a041e5ae67418562a93d80d8)
Signed-off-by: Reynold Xin <rxin@databricks.com>
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala | 4 | ||||
-rw-r--r-- | sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala index dba69659af..5567189c42 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala @@ -163,7 +163,7 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging { if (tmp.nonEmpty) throw e inBacktick = true } else if (char == '.') { - if (tmp.isEmpty) throw e + if (name(i - 1) == '.' || i == name.length - 1) throw e nameParts += tmp.mkString tmp.clear() } else { @@ -172,7 +172,7 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging { } i += 1 } - if (tmp.isEmpty || inBacktick) throw e + if (inBacktick) throw e nameParts += tmp.mkString nameParts.toSeq } diff --git a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala index 8e71ef9683..399ab2bb2e 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala @@ -638,4 +638,11 @@ class DataFrameSuite extends QueryTest { val res11 = TestSQLContext.range(-1).select("id") assert(res11.count == 0) } + + test("SPARK-8621: support empty string column name") { + val df = Seq(Tuple1(1)).toDF("").as("t") + // We should allow empty string as column name + df.col("") + df.col("t.``") + } } |