aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/main/scala
diff options
context:
space:
mode:
authorTakeshi Yamamuro <yamamuro@apache.org>2017-03-05 03:53:19 -0800
committerHerman van Hovell <hvanhovell@databricks.com>2017-03-05 03:53:19 -0800
commit14bb398fae974137c3e38162cefc088e12838258 (patch)
treecb83b0f4b81c86a8a22237d818170247bbc9e825 /sql/core/src/main/scala
parentf48461ab2bdb91cd00efa5a5ec4b0b2bc361e7a2 (diff)
downloadspark-14bb398fae974137c3e38162cefc088e12838258.tar.gz
spark-14bb398fae974137c3e38162cefc088e12838258.tar.bz2
spark-14bb398fae974137c3e38162cefc088e12838258.zip
[SPARK-19254][SQL] Support Seq, Map, and Struct in functions.lit
## What changes were proposed in this pull request? This pr is to support Seq, Map, and Struct in functions.lit; it adds a new IF named `lit2` with `TypeTag` for avoiding type erasure. ## How was this patch tested? Added tests in `LiteralExpressionSuite` Author: Takeshi Yamamuro <yamamuro@apache.org> Author: Takeshi YAMAMURO <linguin.m.s@gmail.com> Closes #16610 from maropu/SPARK-19254.
Diffstat (limited to 'sql/core/src/main/scala')
-rw-r--r--sql/core/src/main/scala/org/apache/spark/sql/functions.scala25
1 files changed, 17 insertions, 8 deletions
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
index 24ed906d33..2247010ac3 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/functions.scala
@@ -91,15 +91,24 @@ object functions {
* @group normal_funcs
* @since 1.3.0
*/
- def lit(literal: Any): Column = {
- literal match {
- case c: Column => return c
- case s: Symbol => return new ColumnName(literal.asInstanceOf[Symbol].name)
- case _ => // continue
- }
+ def lit(literal: Any): Column = typedLit(literal)
- val literalExpr = Literal(literal)
- Column(literalExpr)
+ /**
+ * Creates a [[Column]] of literal value.
+ *
+ * The passed in object is returned directly if it is already a [[Column]].
+ * If the object is a Scala Symbol, it is converted into a [[Column]] also.
+ * Otherwise, a new [[Column]] is created to represent the literal value.
+ * The difference between this function and [[lit]] is that this function
+ * can handle parameterized scala types e.g.: List, Seq and Map.
+ *
+ * @group normal_funcs
+ * @since 2.2.0
+ */
+ def typedLit[T : TypeTag](literal: T): Column = literal match {
+ case c: Column => c
+ case s: Symbol => new ColumnName(s.name)
+ case _ => Column(Literal.create(literal))
}
//////////////////////////////////////////////////////////////////////////////////////////////