Repository: spark
Updated Branches:
  refs/heads/branch-1.4 214550b83 -> 2f85d8ee0


[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 <cloud0...@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 <r...@databricks.com>


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/2f85d8ee
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/2f85d8ee
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/2f85d8ee

Branch: refs/heads/branch-1.4
Commit: 2f85d8ee0c8106c99b9994bf0de2b86233c3f4b4
Parents: 214550b
Author: Wenchen Fan <cloud0...@outlook.com>
Authored: Wed Jul 1 10:31:35 2015 -0700
Committer: Reynold Xin <r...@databricks.com>
Committed: Wed Jul 1 10:31:49 2015 -0700

----------------------------------------------------------------------
 .../apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala | 4 ++--
 .../src/test/scala/org/apache/spark/sql/DataFrameSuite.scala  | 7 +++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/2f85d8ee/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala
----------------------------------------------------------------------
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 dba6965..5567189 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
   }

http://git-wip-us.apache.org/repos/asf/spark/blob/2f85d8ee/sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala
----------------------------------------------------------------------
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 8e71ef9..399ab2b 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.``")
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to