Skip to content

Commit

Permalink
[SPARK-8621] [SQL] support empty string as column name
Browse files Browse the repository at this point in the history
improve the empty check in `parseAttributeName` so that we can allow empty string as column name.
Close apache#7117

Author: Wenchen Fan <cloud0fan@outlook.com>

Closes apache#7149 from cloud-fan/8621 and squashes the following commits:

efa9e3e [Wenchen Fan] support empty string
  • Loading branch information
cloud-fan authored and rxin committed Jul 1, 2015
1 parent 4137f76 commit 31b4a3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,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 {
Expand All @@ -170,7 +170,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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,4 +730,11 @@ class DataFrameSuite extends QueryTest {
val res11 = ctx.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.``")
}
}

0 comments on commit 31b4a3d

Please sign in to comment.