[ 
https://issues.apache.org/jira/browse/ARROW-15996?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17511255#comment-17511255
 ] 

Dragoș Moldovan-Grünfeld commented on ARROW-15996:
--------------------------------------------------

Well spotted. I do need a specific unit - I need to return seconds since that 
is the only unit that overlaps between arrow (supports seconds and lower units) 
and R (supports seconds and higher units: minutes, hours, days, weeks). 
Correct, the chain of casting would not be visible to the end user. But even 
for the developer writing the bindings (or the one needing to correct a 
potential bug), the implementation will look a bit clunky.

{code:r}
strptime -> time64() -> int64() -> divide by 10^9 -> int64() -> duration("s")
{code}

It looks like, since we mapped Arrow's {{duration}} to R's {{difftime}} we no 
longer document {{time32/time64}} mapping to {{{}hms::difftime{}}}, which makes 
me reluctant to rely on it.

This whole issue appeared when I was converting an hms string to difftime. 
There is another option to implement it (besides the chain of casting and 
time32 -> hms::difftime) - the one I was using initially. Use {{strptime}} and 
then subtract {{strptime("0:0:0")}} to get a {{{}duration{}}}.

> [C++] Support casting from time32 and time64 to duration
> --------------------------------------------------------
>
>                 Key: ARROW-15996
>                 URL: https://issues.apache.org/jira/browse/ARROW-15996
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Dragoș Moldovan-Grünfeld
>            Priority: Critical
>
> It would be really helpful if we could convert {{time32}} and {{time64}} to 
> {{duration}}. For example, it could simplify the implementation of some of 
> the R bindings (e.g. {{difftime}}). 
> {code:r}
> library(arrow, warn.conflicts = FALSE)
> a <- Array$create(32000L)
> a
> #> Array
> #> <int32>
> #> [
> #>   32000
> #> ]
> a$cast(time32())
> #> Array
> #> <time32[ms]>
> #> [
> #>   00:00:32.000
> #> ]
> a$cast(int64())$cast(time64())
> #> Array
> #> <time64[ns]>
> #> [
> #>   00:00:00.000032000
> #> ]
> a$cast(time32())$cast(duration())
> #> Error: NotImplemented: Unsupported cast from time32[ms] to duration using 
> function cast_duration
> a$cast(int64())$cast(time64())$cast(duration())
> #> Error: NotImplemented: Unsupported cast from time64[ns] to duration using 
> function cast_duration
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to