Cory Grinstead
10/03/2024, 4:46 PMjay
10/03/2024, 4:52 PMjay
10/03/2024, 4:52 PMCory Grinstead
10/03/2024, 4:57 PMdf = daft.from_pydict({
'date' : ['2021-01-01', '2021-01-02', '2021-01-03'],
}).select(daft.col("date").cast(daft.DataType.date()))
df.select(daft.col("date") + '1y').collect()Cory Grinstead
10/03/2024, 5:01 PMjay
10/03/2024, 5:01 PMCory Grinstead
10/03/2024, 5:02 PMjay
10/03/2024, 5:02 PMjay
10/03/2024, 5:02 PMColin Ho
10/03/2024, 5:17 PMimport daft
import datetime
df = daft.from_pydict(
{
"date": [datetime.date(2021, 1, 1), datetime.date(2021, 1, 2)],
"time_delta": [datetime.timedelta(days=1), datetime.timedelta(days=2)],
}
)
df.with_column("date_plus_time_delta", daft.col("date") + daft.col("time_delta")).show()
when both cols are in the df,
but if you just do daft.col("date") + datetime.timedelta(days=1) it doesn't work because we parse the timedelta lit as a python object.Cory Grinstead
10/03/2024, 5:33 PMCory Grinstead
10/03/2024, 6:56 PMinterval
https://github.com/Eventual-Inc/Daft/pull/2993R. C. Howell
10/03/2024, 10:35 PM<interval> + <datetime>
<datetime> + <interval>
<datetime> - <interval>
Here's the SQL reference for temporal arithmetic. Spark does have a bunch of datetime things like date_add/add_months etc. but they're mostly superfluous and some behave strangely - I'd recommend seeing how far just the SQL standard gets you before introducing any additional scalar functions.