Skip to content

Commit

Permalink
Fixing bugs introduced in latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
schuemie committed Sep 24, 2024
1 parent 1040525 commit 5f1b881
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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,##,<hash><hash>
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%
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-translate-bigquery.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-translate-oracle.R
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
})
4 changes: 2 additions & 2 deletions tests/testthat/test-translate-spark.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down

0 comments on commit 5f1b881

Please sign in to comment.