HyukjinKwon commented on a change in pull request #31207:
URL: https://github.com/apache/spark/pull/31207#discussion_r567365177



##########
File path: python/pyspark/sql/functions.py
##########
@@ -91,13 +92,58 @@ def lit(col):
     Creates a :class:`Column` of literal value.
 
     .. versionadded:: 1.3.0
+    .. versionchanged:: 3.2.0
+        Added support for complex type literals.
+
+    Parameters
+    ----------
+    col : bool, float, int, str, datetime.date, datetime.datetime, dict, list, 
tuple
+        Object to be converted into :class:`Column`.
+
+        If it is a collection, conversion will be applied recursively. In such 
case,
+        all stored values should be of compatible types.
+
+        The passed in object is returned directly if it is already a 
:class:`Column`.
 
     Examples
     --------
     >>> df.select(lit(5).alias('height')).withColumn('spark_user', 
lit(True)).take(1)
     [Row(height=5, spark_user=True)]
-    """
-    return col if isinstance(col, Column) else _invoke_function("lit", col)
+    >>> df.select(
+    ...     lit({"height": 5}).alias("data"),
+    ...     lit(["python", "scala"]).alias("languages")
+    ... ).take(1)
+    [Row(data={'height': 5}, languages=['python', 'scala'])]
+    """
+    if isinstance(col, Column):
+        return col
+
+    elif isinstance(col, list):
+        return array(*[lit(x) for x in col])
+
+    elif isinstance(col, tuple):

Review comment:
       @zero323, can we implement these logics in Scala side, and we simply 
call `lit` here? I think that's more what @maropu meant.
   
   I think the only special case we need to implement in Python side is the 
struct case because 1. `Row` class cannot be passed to JVM side and 2. both 
`list` and `tuple` are converted into `ArrayList` so JVM cannot tell the 
origin. We will probably have to add some comments on that case.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to