Change conversion for difftime to INTERVAL, not TIME#151
Hidden character warning
Conversation
|
Thanks, looks good. Let me sleep over the implications. I wonder what we should return to R land if the database computes a con <- DBI::dbConnect(duckdb::duckdb())
print(DBI::dbGetQuery(con, "select TIME '01:02:03' as t"))
#> t
#> 1 3723 secs
print(DBI::dbGetQuery(con, "select INTERVAL 1 HOUR as t"))
#> t
#> 1 3600 secs
print(DBI::dbGetQuery(con, "select INTERVAL 1.2 HOUR as t"))
#> Error: {"exception_type":"Parser","exception_message":"syntax error at or near \"1.2\"","position":"16","error_subtype":"SYNTAX_ERROR"}Created on 2024-04-30 with reprex v2.1.0 |
|
we've always returned |
krlmlr
left a comment
There was a problem hiding this comment.
Looks good, just one question.
| dtime_t RTimeSecondsType::Convert(double val) { | ||
| return dtime_t(int64_t(val * Interval::MICROS_PER_SEC)); | ||
| interval_t RIntervalSecondsType::Convert(double val) { | ||
| return Interval::FromMicro(int64_t(val * Interval::MICROS_PER_SEC)); |
There was a problem hiding this comment.
This is consistent with the old implementation, but when converting datetimes I think we're rounding. Should we change this as part of the change here and further below?
| return Interval::FromMicro(int64_t(val * Interval::MICROS_PER_SEC)); | |
| return Interval::FromMicro(int64_t(round(val * Interval::MICROS_PER_SEC))); |
|
How do I construct a literal interval of 1.5 hours? I'll try to formulate issues upstream. |
|
No more objections after reading the docs. Tests are failing locally, need to investigate. |
|
Thanks, part of the CRAN release just submitted. |
This PR changes the DuckDB representation of
difftimeR objects fromTIMEtoINTERVAL. The reasoning here is that R's difftime can represent way larger time differences than single days, which is whatTIMEis for. This goes wrong if the difftime is longer than one day and one tries for example casting the value to a string.Here is an example that demonstrates the problem
Currently, this returns random garbage for the string
and triggers an assertion when built in debug mode.
With this PR, it returns