aboutsummaryrefslogtreecommitdiff
path: root/sql/core/src/main/scala/org
diff options
context:
space:
mode:
Diffstat (limited to 'sql/core/src/main/scala/org')
-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))
}
//////////////////////////////////////////////////////////////////////////////////////////////