apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
5.49k stars 1.02k forks source link

Allow casting durations to different timeunits #11097

Open simonvandel opened 1 week ago

simonvandel commented 1 week ago

Is your feature request related to a problem or challenge?

I would like to be able to cast a duration to a different timeunit. Current behavior:

DataFusion CLI v39.0.0
> SELECT arrow_cast(1, 'Duration(Millisecond)');
+----------------------------------------------------+
| arrow_cast(Int64(1),Utf8("Duration(Millisecond)")) |
+----------------------------------------------------+
| 0 days 0 hours 0 mins 0.001 secs                   |
+----------------------------------------------------+
1 row(s) fetched. 
Elapsed 0.065 seconds.

> SELECT arrow_cast(arrow_cast(1, 'Duration(Millisecond)'), 'Duration(Second)');

This feature is not implemented: Unsupported CAST from Duration(Millisecond) to Duration(Second)

Describe the solution you'd like

The cast works

Describe alternatives you've considered

No response

Additional context

No response

alamb commented 6 days ago

This makes sense -- the easist way would be to add support in the arrow cast kernels

Looks like only Int --> Duration is supported now

https://github.com/apache/arrow-rs/blob/0a4d8a14b58e45ef92e31541f0b51a5b25de5f10/arrow-cast/src/cast/mod.rs#L274-L275