does daft support date math? in pyspark, you have...
# daft-dev
c
does daft support date math? in pyspark, you have date_add and add_months, but I don't see an equivalent in daft.
j
We do, I think its just arithmetic ops on DURATION and Datetime types @Colin Ho would know more!
We don’t have dedicated functions though
c
that doesn't seem to work on date fields
Copy code
df = 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()
👀 1
j
Thanks! I’m guessing this is a blocker for the TPCH questions?
c
yes, this and this
j
Let’s put together a list of needs for Mim’s TPCH notebook? We can try to match @Colin Ho on his release of streaming executor as well so we make both work at the same time
Aha one step ahead of me :)
c
so, doing temporal arithmetic like this works:
Copy code
import 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.
c
here's a PR to fix the error message https://github.com/Eventual-Inc/Daft/pull/2990
🙌 1
Here's a PR to support sql
interval
https://github.com/Eventual-Inc/Daft/pull/2993
🔥 1
r
SQL defines just +/- with intervals so hopefully that covers you for all tpc things.
Copy code
<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.
🙌 1