chmp opened a new issue, #10082:
URL: https://github.com/apache/arrow-datafusion/issues/10082

   ### Is your feature request related to a problem or challenge?
   
   I would like to get the number of seconds elapsed of a duration, that is the 
result of the subtraction of two `Timestamp` columns. The resulting unit is 
controlled by datafusion and hence unknown to me.
   
   ### Describe the solution you'd like
   
   I would would like to cast between durations of different types. This 
feature does not seem to be implemented:
   
   ```sql
   SELECT arrow_cast(arrow_cast(1, 'Duration(Microsecond)'), 
'Duration(Second)') as value;
   -- This feature is not implemented: Unsupported CAST from 
Duration(Microsecond) to Duration(Second)
   ```
   
   I would expect the same behavior as casting between timestamps:
   
   ```sql
   SELECT arrow_cast(arrow_cast(arrow_cast(24 * 60 * 60, 'Timestamp(Second, 
None)'), 'Timestamp(Millisecond, None)'), 'Int64') as value;
   -- +----------+
   -- | value    |
   -- +----------+
   -- | 86400000 |
   -- +----------+
   -- 1 row in set. Query took 0.003 seconds.
   ```
   
   ### Describe alternatives you've considered
   
   My initial attempt was to divide the resulting duration by a known reference 
duration. However this resulted in a planning error:
   
   ```sql
   SELECT arrow_cast(1, 'Duration(Microsecond)') /  arrow_cast(1, 
'Duration(Microsecond)') as value;
   -- Error during planning: Cannot coerce arithmetic expression 
Duration(Microsecond) / Duration(Microsecond) to valid types
   ```
   
   An alternative would be to cast the duration to an `Int64`. However, this 
operation simply discards the time unit of the duration. If the duration value 
is an outcome of a datafusion operation the unit is, at least to my knowledge, 
not defined. Therefore this operation is potentially dangerous.
   
   ### Additional context
   
   All examples are using `DataFusion CLI v37.0.0`. If you point me in the 
right direction, I would be happy to implement a PR.


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

Reply via email to