From c7a6d02112a188e99bd59d7a35c92a69e564f0bb Mon Sep 17 00:00:00 2001 From: Adam Black Date: Thu, 31 Oct 2024 14:36:45 +0100 Subject: [PATCH] fix `add_years()` translation on spark (#1511) --- NEWS.md | 1 + R/backend-spark-sql.R | 2 +- tests/testthat/test-backend-spark-sql.R | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index fc76ea9bb..bf959d524 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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). diff --git a/R/backend-spark-sql.R b/R/backend-spark-sql.R index c551f830a..88de3f7a5 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 5332457d3..4a005abf1 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)"))