Skip to content

Commit efa9e3e

Browse files
committed
support empty string
1 parent 64c1461 commit efa9e3e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
161161
if (tmp.nonEmpty) throw e
162162
inBacktick = true
163163
} else if (char == '.') {
164-
if (tmp.isEmpty) throw e
164+
if (name(i - 1) == '.' || i == name.length - 1) throw e
165165
nameParts += tmp.mkString
166166
tmp.clear()
167167
} else {
@@ -170,7 +170,7 @@ abstract class LogicalPlan extends QueryPlan[LogicalPlan] with Logging {
170170
}
171171
i += 1
172172
}
173-
if (tmp.isEmpty || inBacktick) throw e
173+
if (inBacktick) throw e
174174
nameParts += tmp.mkString
175175
nameParts.toSeq
176176
}

sql/core/src/test/scala/org/apache/spark/sql/DataFrameSuite.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,4 +730,11 @@ class DataFrameSuite extends QueryTest {
730730
val res11 = ctx.range(-1).select("id")
731731
assert(res11.count == 0)
732732
}
733+
734+
test("SPARK-8621: support empty string column name") {
735+
val df = Seq(Tuple1(1)).toDF("").as("t")
736+
// We should allow empty string as column name
737+
df.col("")
738+
df.col("t.``")
739+
}
733740
}

0 commit comments

Comments
 (0)