Skip to content

Commit

Permalink
[CHORE] Concretize casting semantics for temporal + decimal types (#2798
Browse files Browse the repository at this point in the history
)

Closes: #1173

This PR makes the casting logic for temporal + decimal types more strict
and transparent. All target datatypes for casting is now contained in
the `.cast` method, removing the catch all branch which allowed casting
via the underlying physical type, e.g. you used to be able to cast a
Duration to a Timestamp by simply casting the underlying I64 array to a
timestamp array.

Additionally, this PR removes the `arrow_logical_cast` function, which
was essentially used for two things:
1. casting temporal types to the same temporal type, but with different
timeunit / timezone,
2. casting decimals to anything else.

Now, the logic for same type different timeunit / timezone casting is
built into Daft, instead of using Arrow2. The decimal to decimal logic,
however, is still via Arrow2 (as it is more complex and will require
it's own PR). Nevertheless, the code is much cleaner and easier to
understand.

NOTE: This PR is a breaking change, as it will likely reduce the number
of possible cast targets for these types.

---------

Co-authored-by: Colin Ho <[email protected]>
Co-authored-by: Colin Ho <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2024
1 parent 3980f12 commit 4ddc283
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 221 deletions.
8 changes: 4 additions & 4 deletions daft/expressions/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,13 @@ def cast(self, dtype: DataType) -> Expression:
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
| Map | N | N | N | N | N | N | N | N | N | N | Y | N | N | N | Y | Y | N | Y | N | N | N | N |
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
| Timestamp | Y | Y | Y | Y | Y | Y | Y | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | Y | N |
| Timestamp | Y | N | Y | Y | N | Y | N | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | Y | N |
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
| Date | Y | Y | Y | Y | Y | Y | Y | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | N | N |
| Date | Y | N | Y | Y | N | Y | N | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | N | N |
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
| Time | Y | Y | Y | Y | Y | Y | Y | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | Y | Y |
| Time | Y | N | Y | Y | N | Y | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | Y | N |
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
| Duration | Y | Y | Y | Y | Y | Y | Y | N | N | N | N | N | N | Y | N | N | N | N | Y | Y | Y | Y |
| Duration | Y | N | Y | Y | N | N | N | N | N | N | N | N | N | Y | N | N | N | N | N | N | N | N |
+--------------------+------+---------+----------+--------+------------+--------+--------+-------------------+-------+-------------------+-----------+--------+--------------------+--------+------+-----------------+--------+-----+-----------+------+------+----------+
Note:
Expand Down
Loading

0 comments on commit 4ddc283

Please sign in to comment.