itholic opened a new pull request, #37722:
URL: https://github.com/apache/spark/pull/37722
### What changes were proposed in this pull request?
This PR proposes to support `list` type for `pyspark.sql.functions.lit`.
### Why are the changes needed?
To improve the API usability.
### Does this PR introduce _any_ user-facing change?
Yes, now the `list` type is available for `pyspark.sql.functions.list` as
below:
- Before
```python
>>> spark.range(3).withColumn("c", lit([1,2,3])).show()
Traceback (most recent call last):
...
: org.apache.spark.SparkRuntimeException: [UNSUPPORTED_FEATURE.LITERAL_TYPE]
The feature is not supported: Literal for '[1, 2, 3]' of class
java.util.ArrayList.
at
org.apache.spark.sql.errors.QueryExecutionErrors$.literalTypeUnsupportedError(QueryExecutionErrors.scala:302)
at
org.apache.spark.sql.catalyst.expressions.Literal$.apply(literals.scala:100)
at org.apache.spark.sql.functions$.lit(functions.scala:125)
at org.apache.spark.sql.functions.lit(functions.scala)
at
java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
at java.base/java.lang.reflect.Method.invoke(Method.java:577)
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:374)
at py4j.Gateway.invoke(Gateway.java:282)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at
py4j.ClientServerConnection.waitForCommands(ClientServerConnection.java:182)
at py4j.ClientServerConnection.run(ClientServerConnection.java:106)
at java.base/java.lang.Thread.run(Thread.java:833)
```
- After
```python
>>> spark.range(3).withColumn("c", lit([1,2,3])).show()
+---+---------+
| id| c|
+---+---------+
| 0|[1, 2, 3]|
| 1|[1, 2, 3]|
| 2|[1, 2, 3]|
+---+---------+
```
### How was this patch tested?
Added doctest & unit test.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]