-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change conversion for difftime to INTERVAL, not TIME #151
The head ref may contain hidden characters: "timeinterval\u00A0"
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just one question.
src/types.cpp
Outdated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
difftime
R objects fromTIME
toINTERVAL
. The reasoning here is that R's difftime can represent way larger time differences than single days, which is whatTIME
is 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