From b64ac1a7169f8323f09f1dd395df69f325d72c44 Mon Sep 17 00:00:00 2001 From: Admin_asena5 Date: Thu, 1 Aug 2024 16:50:21 -0400 Subject: [PATCH] Fix bug --- inst/csv/replacementPatterns.csv | 2 +- tests/testthat/test-translate-spark.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/inst/csv/replacementPatterns.csv b/inst/csv/replacementPatterns.csv index f0a551d..8a14f1c 100644 --- a/inst/csv/replacementPatterns.csv +++ b/inst/csv/replacementPatterns.csv @@ -1140,7 +1140,7 @@ spark,"WITH @cte AS (SELECT @s1 '@literal' @s2)","WITH @cte AS (SELECT @s1 CAST( spark,UPDATE STATISTICS @a;, spark,"SELECT @columns FROM (@a) @x,(@b) @y;","SELECT @columns FROM (@a) @x cross join (@b) @y;" spark,"ALTER TABLE @table ADD COLUMN @([\w_-]+)column @type DEFAULT @default;","ALTER TABLE @table ADD COLUMN @column @type; \nALTER TABLE @table SET TBLPROPERTIES('delta.feature.allowColumnDefaults' = 'supported'); \nALTER TABLE @table ALTER COLUMN @column SET DEFAULT @default;" -spark,"CAST(@a AS DATE)","IF(try_cast(@a AS DATE) IS NULL, to_date(cast(@a AS STRING), 'yyyyMMdd'), CAST(@a AS DATE))" +spark,"CAST(@a AS DATE)","IF(try_cast(@a AS DATE) IS NULL, to_date(cast(@a AS STRING), 'yyyyMMdd'), try_cast(@a AS DATE))" sqlite extended,"IIF(@condition, @whentrue, @whenfalse)","CASE WHEN @condition THEN @whentrue ELSE @whenfalse END" sqlite extended,"ROUND(@a,@b)","ROUND(CAST(@a AS REAL),@b)" sqlite extended,+ '@a',|| '@a' diff --git a/tests/testthat/test-translate-spark.R b/tests/testthat/test-translate-spark.R index e9834c6..3f4d7e9 100644 --- a/tests/testthat/test-translate-spark.R +++ b/tests/testthat/test-translate-spark.R @@ -451,5 +451,5 @@ test_that("translate sql server -> spark add column with default", { test_that("translate sql server -> spark cast string as date", { sql <- translate("SELECT CAST('20191201' AS DATE);", targetDialect = "spark") - expect_equal_ignore_spaces(sql, "SELECT IF(try_cast('20191201' AS DATE) IS NULL, to_date(cast('20191201' AS STRING), 'yyyyMMdd'), CAST('20191201' AS DATE));") + expect_equal_ignore_spaces(sql, "SELECT IF(try_cast('20191201' AS DATE) IS NULL, to_date(cast('20191201' AS STRING), 'yyyyMMdd'), try_cast('20191201' AS DATE))") })