Skip to content
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

feat: round() duckdb translation uses ROUND_EVEN() instead of ROUND() #157

Merged
merged 4 commits into from
May 27, 2024

Conversation

lschneiderbauer
Copy link
Contributor

@lschneiderbauer lschneiderbauer commented May 5, 2024

  • In addition, I adjusted the default value of the digits argument in round() to round(x, digits = 0) to be consistent with the R default value.

Fixes #146

Copy link
Collaborator

@krlmlr krlmlr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, great!

@@ -160,7 +160,7 @@ sql_translation.duckdb_connection <- function(con) {
regexpr = function(p, x) {
build_sql("(CASE WHEN REGEXP_MATCHES(", x, ", ", p, ") THEN (LENGTH(LIST_EXTRACT(STRING_SPLIT_REGEX(", x, ", ", p, "), 0))+1) ELSE -1 END)")
},
round = function(x, digits) sql_expr(ROUND(!!x, CAST(ROUND((!!digits), 0L) %AS% INTEGER))),
round = function(x, digits = 0) sql_expr(ROUND_EVEN(!!x, CAST(ROUND((!!digits), 0L) %AS% INTEGER))),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want a test for calling round() with a single argument?

@krlmlr krlmlr changed the title round() duckdb translation: use round_even() instead of round() feat: round() duckdb translation uses ROUND_EVEN() instead of ROUND() May 22, 2024
@krlmlr krlmlr merged commit 40d6c8f into duckdb:main May 27, 2024
24 checks passed
@krlmlr
Copy link
Collaborator

krlmlr commented May 27, 2024

Thanks! Let's add that missing test later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

round() semantics of R-version differs from its duckdb-translation
2 participants