Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions R/TrexDialect.R
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
#' Switch SQL dialect for Trex connection
#'
#' This function conditionally switches the SQL dialect to DuckDB for
#' when the 'trex_connection' environment variable is set to "true".
#' This function conditionally switches the SQL dialect based on the
#' value of the 'trex_connection' environment variable. Supported values:
#' "trex", "trex_hana" (or unset).
#'
#' - If 'trex_connection' is not set, returns the original dialect.
#' - If 'trex_connection' == "trex" and dialect != "hana", returns "duckdb".
#' - If 'trex_connection' == "trex_hana", returns "hana".
#' - For any other value, returns the original dialect.
#'
#' @param dialect A character string specifying the original SQL dialect
#' (e.g., "postgresql", "mysql", "sqlite", etc.)
#'
#' @return A character string representing the SQL dialect to use:
#' \itemize{
#' \item Returns "duckdb" if trex_connection environment variable is "true" and dialect is not "hana"
#' \item Returns the original dialect otherwise
#' \item If 'trex_connection' is not set, returns the original dialect
#' \item If 'trex_connection' == "trex" and dialect != "hana", returns "duckdb"
#' \item If 'trex_connection' == "trex_hana", returns "hana"
#' \item For any other value, returns the original dialect
#' }
#'
#' @details
#' The function checks the 'trex_connection' environment variable:
#' \itemize{
#' \item If the environment variable is not set (NA), returns the original dialect
#' \item If set to "true" and the dialect is not "hana", returns "duckdb"
#' \item If set to "trex" and the dialect is not "hana", returns "duckdb"
#' \item If set to "trex_hana", returns "hana"
#' \item Otherwise, returns the original dialect unchanged
#' }
#'
#' @examples
#' # Set environment variable for testing
#' Sys.setenv(trex_connection = "true")
#' Sys.setenv(trex_connection = "trex")
#' trexDialect("postgresql") # Returns "duckdb"
#' trexDialect("hana") # Returns "hana" (unchanged)
#'
#' # Unset environment variable
#' Sys.setenv(trex_connection = "trex_hana")
#' trexDialect("postgresql") # Returns "hana"
#' trexDialect("hana") # Returns "hana"
#'
#' Sys.setenv(trex_connection = "other_value")
#' trexDialect("postgresql") # Returns "postgresql"
#'
#' Sys.unsetenv("trex_connection")
#' trexDialect("postgresql") # Returns "postgresql"
#'
Expand All @@ -38,9 +53,11 @@ trexDialect <- function(dialect) {
if (is.na(trex_env)) {
return(dialect)
}
if (trex_env == "true" && dialect != "hana") {
return("duckdb")
} else {
return(dialect)
}
if (trex_env == "trex" && dialect != "hana") {
return("duckdb")
} else if (trex_env == "trex_hana") {
return("hana")
} else {
return(dialect)
}
}
6 changes: 3 additions & 3 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1480,10 +1480,10 @@ hana,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);","D
hana,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table')) THEN DROP TABLE @table; END IF; END;"
hana,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE @table;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table')) THEN DROP TABLE @table; END IF; END;"
hana,"DROP TABLE IF EXISTS @table_name;","DO BEGIN IF EXISTS (SELECT * FROM (SELECT SCHEMA_NAME || '.' || TABLE_NAME AS combined_name, SCHEMA_NAME, TABLE_NAME FROM tables) WHERE combined_name=UPPER('@table_name')) THEN DROP TABLE @table_name; END IF; END;"
hana,CREATE TABLE #@table (@definition);,CREATE LOCAL TEMPORARY TABLE #@table (@definition);
hana,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE LOCAL TEMPORARY TABLE #@d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e);
hana,CREATE TABLE #@table (@definition);,CREATE TABLE #@table (@definition);
hana,WITH @a AS @b SELECT @c INTO #@d FROM @e;,CREATE TABLE #@d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e);
hana,WITH @a AS @b SELECT @c INTO @d FROM @e;,CREATE TABLE @d\nAS(\nWITH @a AS @b SELECT\n@c\nFROM\n@e);
hana,SELECT @a INTO #@b FROM @c;,CREATE LOCAL TEMPORARY TABLE #@b AS(\nSELECT\n@a\nFROM\n@c);
hana,SELECT @a INTO #@b FROM @c;,CREATE TABLE #@b AS(\nSELECT\n@a\nFROM\n@c);
hana,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS(\nSELECT\n@a\nFROM\n@c);
hana,SELECT @a INTO @b;,CREATE TABLE @b AS\nSELECT\n@a;
hana,#,<hash><hash>
Expand Down
Binary file added inst/java/SqlRender-1.19.2-SNAPSHOT.jar
Binary file not shown.
Binary file modified inst/java/SqlRender.jar
Binary file not shown.
Loading