Skip to content

Commit

Permalink
fix add_years() translation on spark (#1511)
Browse files Browse the repository at this point in the history
  • Loading branch information
ablack3 authored Oct 31, 2024
1 parent 7fb52d7 commit c7a6d02
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

* `across(everything())` doesn't select grouping columns created via `.by` in
`summarise()` (@mgirlich, #1493).
* `clock::add_years()` translates to correct SQL on Spark (@ablack3, #1510).

* New translations of clock function `date_count_between()` for SQL server, Redshift, Snowflake, Postgres, and Spark (@edward-burn, #1495).

Expand Down
2 changes: 1 addition & 1 deletion R/backend-spark-sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ simulate_spark_sql <- function() simulate_dbi("Spark SQL")
},
add_years = function(x, n, ...) {
check_dots_empty()
sql_expr(add_months(!!!x, !!n*12))
sql_expr(add_months(!!x, !!n*12))
},
date_build = function(year, month = 1L, day = 1L, ..., invalid = NULL) {
sql_expr(make_date(!!year, !!month, !!day))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-backend-spark-sql.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test_that("custom clock functions translated correctly", {
local_con(simulate_spark_sql())
expect_equal(test_translate_sql(add_years(x, 1)), sql("ADD_MONTHS('`x`', 1.0 * 12.0)"))
expect_equal(test_translate_sql(add_years(x, 1)), sql("ADD_MONTHS(`x`, 1.0 * 12.0)"))
expect_equal(test_translate_sql(add_days(x, 1)), sql("DATE_ADD(`x`, 1.0)"))
expect_error(test_translate_sql(add_days(x, 1, "dots", "must", "be empty")))
expect_equal(test_translate_sql(date_build(2020, 1, 1)), sql("MAKE_DATE(2020.0, 1.0, 1.0)"))
Expand Down

0 comments on commit c7a6d02

Please sign in to comment.