HyukjinKwon opened a new pull request #34614:
URL: https://github.com/apache/spark/pull/34614


   ### What changes were proposed in this pull request?
   
   This PR implements `DayTimeIntervalType` in PySpark's `DataFrame.collect()`, 
`SparkSession.createDataFrame()` and `functions.udf`.
   This type is mapped to 
[`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#timedelta-objects).
   
   Arrow code path will be separately implemented at SPARK-37277, and Py4J 
support will be done at SPARK-37281.
   
   ### Why are the changes needed?
   
   - In order to support `datetime.timedelta` out of the box via PySpark.
   - To seamlessly support ANSI standard types
   
   Semantically 
[`datetime.timedelta`](https://docs.python.org/3/library/datetime.html#timedelta-objects)
 is mapped to `DayTimeIntervalType`. Python's timedelta does not support 
months, years, etc.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, users will be able to use `datetime.timedelta` in PySpark with 
`DayTimeIntervalType` at `DataFrame.collect()`, 
`SparkSession.createDataFrame()` and `functions.udf`:
   
   ```python
   >>> import datetime
   >>> df = spark.createDataFrame([(datetime.timedelta(days=1),)])
   >>> df.collect()
   [Row(_1=datetime.timedelta(days=1))]
   ```
   
   ```python
   >>> from pyspark.sql.functions import udf
   >>> df.select(udf(lambda x: x, "interval day to second")("_1")).show()
   +--------------------+
   |        <lambda>(_1)|
   +--------------------+
   |INTERVAL '1 00:00...|
   +--------------------+
   ```
   
   ### How was this patch tested?
   
   Unittests were added, and the


-- 
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]

Reply via email to