From 50d30802062596a47a42de5883acb6ce6a586b52 Mon Sep 17 00:00:00 2001 From: Adam Black Date: Wed, 5 Jun 2024 17:15:45 +0200 Subject: [PATCH] fix date_build translation on redshift --- R/backend-redshift.R | 2 +- tests/testthat/test-backend-redshift.R | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/R/backend-redshift.R b/R/backend-redshift.R index b3f35d3c5..7681a8848 100644 --- a/R/backend-redshift.R +++ b/R/backend-redshift.R @@ -72,7 +72,7 @@ sql_translation.RedshiftConnection <- function(con) { sql_expr(DATEADD(YEAR, !!n, !!x)) }, date_build = function(year, month = 1L, day = 1L, ..., invalid = NULL) { - glue_sql2(sql_current_con(), "TO_DATE(CAST({.val year} AS TEXT) || '-' CAST({.val month} AS TEXT) || '-' || CAST({.val day} AS TEXT)), 'YYYY-MM-DD')") + glue_sql2(sql_current_con(), "TO_DATE(CAST({.val year} AS TEXT) || '-' || CAST({.val month} AS TEXT) || '-' || CAST({.val day} AS TEXT), 'YYYY-MM-DD')") }, get_year = function(x) { sql_expr(DATE_PART('year', !!x)) diff --git a/tests/testthat/test-backend-redshift.R b/tests/testthat/test-backend-redshift.R index f2b5a9699..d81bf8d53 100644 --- a/tests/testthat/test-backend-redshift.R +++ b/tests/testthat/test-backend-redshift.R @@ -63,8 +63,8 @@ test_that("custom clock functions translated correctly", { expect_equal(test_translate_sql(add_years(x, 1)), sql("DATEADD(YEAR, 1.0, `x`)")) expect_equal(test_translate_sql(add_days(x, 1)), sql("DATEADD(DAY, 1.0, `x`)")) expect_error(test_translate_sql(add_days(x, 1, "dots", "must", "be empty"))) - expect_equal(test_translate_sql(date_build(2020, 1, 1)), sql("TO_DATE(CAST(2020.0 AS TEXT) || '-' CAST(1.0 AS TEXT) || '-' || CAST(1.0 AS TEXT)), 'YYYY-MM-DD')")) - expect_equal(test_translate_sql(date_build(year_column, 1L, 1L)), sql("TO_DATE(CAST(`year_column` AS TEXT) || '-' CAST(1 AS TEXT) || '-' || CAST(1 AS TEXT)), 'YYYY-MM-DD')")) + expect_equal(test_translate_sql(date_build(2020, 1, 1)), sql("TO_DATE(CAST(2020.0 AS TEXT) || '-' || CAST(1.0 AS TEXT) || '-' || CAST(1.0 AS TEXT), 'YYYY-MM-DD')")) + expect_equal(test_translate_sql(date_build(year_column, 1L, 1L)), sql("TO_DATE(CAST(`year_column` AS TEXT) || '-' || CAST(1 AS TEXT) || '-' || CAST(1 AS TEXT), 'YYYY-MM-DD')")) expect_equal(test_translate_sql(get_year(date_column)), sql("DATE_PART('year', `date_column`)")) expect_equal(test_translate_sql(get_month(date_column)), sql("DATE_PART('month', `date_column`)")) expect_equal(test_translate_sql(get_day(date_column)), sql("DATE_PART('day', `date_column`)"))