From b1153b7c083253a15da02a02c974fc8d8345c7d7 Mon Sep 17 00:00:00 2001 From: Adam Black Date: Wed, 5 Jun 2024 15:44:55 +0200 Subject: [PATCH 1/2] Fix add_years translation on spark --- R/backend-spark-sql.R | 2 +- tests/testthat/test-backend-spark-sql.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/R/backend-spark-sql.R b/R/backend-spark-sql.R index 8cd9288d1..7a690418d 100644 --- a/R/backend-spark-sql.R +++ b/R/backend-spark-sql.R @@ -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)) diff --git a/tests/testthat/test-backend-spark-sql.R b/tests/testthat/test-backend-spark-sql.R index e1276c7a0..196f6deda 100644 --- a/tests/testthat/test-backend-spark-sql.R +++ b/tests/testthat/test-backend-spark-sql.R @@ -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)")) From 1617c0a2f645c9d0e8f83eddca0caf140cc94294 Mon Sep 17 00:00:00 2001 From: Adam Black Date: Mon, 28 Oct 2024 16:18:19 +0100 Subject: [PATCH 2/2] add news entry for issue #1510 --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index dae72d35d..77161dd50 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,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). # dbplyr 2.5.0