diff --git a/inst/csv/replacementPatterns.csv b/inst/csv/replacementPatterns.csv index 2649cd4..d45d8e2 100644 --- a/inst/csv/replacementPatterns.csv +++ b/inst/csv/replacementPatterns.csv @@ -119,7 +119,7 @@ oracle,WITH @a AS @b INSERT INTO @c SELECT @d;,INSERT INTO @c WITH @a AS @b SELE oracle,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS\nSELECT\n@a\nFROM\n@c; oracle,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a; oracle,##, -oracle,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%table;\nCREATE TABLE %temp_prefix%%session_id%table +oracle,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%@table;\nCREATE TABLE %temp_prefix%%session_id%@table oracle,#@([^\s]+)table.@([^\s]+)field,%session_id%@table.@field oracle,"DROP TABLE IF EXISTS #@table;",BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE %temp_prefix%%session_id%@table';\n EXECUTE IMMEDIATE 'DROP TABLE %temp_prefix%%session_id%@table';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND; oracle,#,%temp_prefix%%session_id% @@ -807,7 +807,7 @@ bigquery,DEFAULT @([0-9]+)a,"" bigquery,DEFAULT \"@a\","" bigquery,"DEFAULT CURRENT_DATE()","" bigquery,TRUNCATE TABLE @a;,DELETE FROM @a WHERE True; -bigquery,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%table;\nCREATE TABLE %temp_prefix%%session_id%table +bigquery,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%@table;\nCREATE TABLE %temp_prefix%%session_id%@table bigquery,#@([^\s]+)table.@([^\s]+)field,%session_id%@table.@field bigquery,#,%temp_prefix%%session_id% bigquery,CREATE INDEX @index_name ON @table_col_cond;,-- bigquery does not support indexes @@ -1082,7 +1082,7 @@ spark,SELECT @a INTO @b GROUP BY @c;,CREATE TABLE @b\nUSING DELTA\n AS\nSELECT\n spark,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table\nUSING DELTA\nAS\n@definition;",CREATE TABLE IF NOT EXISTS @table\nUSING DELTA\nAS\n@definition; spark,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",CREATE TABLE IF NOT EXISTS @table (@definition); spark,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table; -spark,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%table;\nCREATE TABLE %temp_prefix%%session_id%table +spark,CREATE TABLE #@([^\s]+)table,DROP TABLE IF EXISTS %temp_prefix%%session_id%@table;\nCREATE TABLE %temp_prefix%%session_id%@table spark,#,%temp_prefix%%session_id% spark,\"@a\",`@a` spark,+ '@a',|| '@a' diff --git a/tests/testthat/test-translate-bigquery.R b/tests/testthat/test-translate-bigquery.R index 1522aff..01c8a88 100644 --- a/tests/testthat/test-translate-bigquery.R +++ b/tests/testthat/test-translate-bigquery.R @@ -552,12 +552,12 @@ test_that("translate sql server -> bigquery RIGHT with implicit concat", { test_that("translate sql server -> bigquery create temp table", { sql <- translate("CREATE TABLE #temp (x INT);", targetDialect = "bigquery", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stable;\nCREATE TABLE ts.%stable (x INT64);", getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stemp;\nCREATE TABLE ts.%stemp (x INT64);", getTempTablePrefix(), getTempTablePrefix())) }) test_that("translate sql server -> bigquery select into temp table", { sql <- translate("SELECT * INTO #temp FROM my_table;", targetDialect = "bigquery", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stable;\nCREATE TABLE ts.%stable AS\nSELECT\n* \nFROM\nmy_table;", getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stemp;\nCREATE TABLE ts.%stemp AS\nSELECT\n* \nFROM\nmy_table;", getTempTablePrefix(), getTempTablePrefix())) }) test_that("translate sql server -> bigquery create temp table if not exists", { diff --git a/tests/testthat/test-translate-oracle.R b/tests/testthat/test-translate-oracle.R index 706304f..1225814 100644 --- a/tests/testthat/test-translate-oracle.R +++ b/tests/testthat/test-translate-oracle.R @@ -564,10 +564,10 @@ test_that("translate sql server -> oracle bitwise and", { test_that("translate sql server -> oracle create temp table", { sql <- translate("CREATE TABLE #temp (x INT);", targetDialect = "oracle", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE ts.%stable';\n EXECUTE IMMEDIATE 'DROP TABLE ts.%stable';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;\nCREATE TABLE ts.%stable (x INT);", getTempTablePrefix(), getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE ts.%stemp';\n EXECUTE IMMEDIATE 'DROP TABLE ts.%stemp';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;\nCREATE TABLE ts.%stemp (x INT);", getTempTablePrefix(), getTempTablePrefix(), getTempTablePrefix())) }) test_that("translate sql server -> oracle select into temp table", { sql <- translate("SELECT * INTO #temp FROM my_table;", targetDialect = "oracle", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE ts.%stable';\n EXECUTE IMMEDIATE 'DROP TABLE ts.%stable';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;\nCREATE TABLE ts.%stable AS\nSELECT\n* \nFROM\nmy_table ;", getTempTablePrefix(), getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("BEGIN\n EXECUTE IMMEDIATE 'TRUNCATE TABLE ts.%stemp';\n EXECUTE IMMEDIATE 'DROP TABLE ts.%stemp';\nEXCEPTION\n WHEN OTHERS THEN\n IF SQLCODE != -942 THEN\n RAISE;\n END IF;\nEND;\nCREATE TABLE ts.%stemp AS\nSELECT\n* \nFROM\nmy_table ;", getTempTablePrefix(), getTempTablePrefix(), getTempTablePrefix())) }) diff --git a/tests/testthat/test-translate-spark.R b/tests/testthat/test-translate-spark.R index 6af23a1..79967d2 100644 --- a/tests/testthat/test-translate-spark.R +++ b/tests/testthat/test-translate-spark.R @@ -456,12 +456,12 @@ test_that("translate sql server -> spark cast string as date", { test_that("translate sql server -> spark create temp table", { sql <- translate("CREATE TABLE #temp (x INT);", targetDialect = "spark", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stable;\nCREATE TABLE ts.%stable \nUSING DELTA\n AS\nSELECT\nCAST(NULL AS int) AS x WHERE 1 = 0;", getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stemp;\nCREATE TABLE ts.%stemp \nUSING DELTA\n AS\nSELECT\nCAST(NULL AS int) AS x WHERE 1 = 0;", getTempTablePrefix(), getTempTablePrefix())) }) test_that("translate sql server -> spark select into temp table", { sql <- translate("SELECT * INTO #temp FROM my_table;", targetDialect = "spark", tempEmulationSchema = "ts") - expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stable;\nCREATE TABLE ts.%stable \nUSING DELTA\nAS\nSELECT\n* \nFROM\nmy_table;", getTempTablePrefix(), getTempTablePrefix())) + expect_equal_ignore_spaces(sql, sprintf("DROP TABLE IF EXISTS ts.%stemp;\nCREATE TABLE ts.%stemp \nUSING DELTA\nAS\nSELECT\n* \nFROM\nmy_table;", getTempTablePrefix(), getTempTablePrefix())) }) test_that("translate sql server -> spark create temp table if not exists", {