Skip to content

Commit

Permalink
Merge pull request #377 from intersystems-community/main
Browse files Browse the repository at this point in the history
Add support for InterSystems IRIS as an additional database platform
  • Loading branch information
schuemie authored Sep 30, 2024
2 parents 28cb10c + 3136e9f commit e5463e2
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ jobs:
- name: Download package tarball
if: ${{ env.new_version != '' }}
uses: actions/download-artifact@v2
uses: actions/download-artifact@v4.1.7
with:
name: package_tarball

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Maintainer: Martijn Schuemie <[email protected]>
Description: A rendering tool for parameterized SQL that also translates into
different SQL dialects. These dialects include 'Microsoft SQL Server', 'Oracle',
'PostgreSql', 'Amazon RedShift', 'Apache Impala', 'IBM Netezza', 'Google BigQuery', 'Microsoft PDW', 'Snowflake',
'Azure Synapse Analytics Dedicated', 'Apache Spark', and 'SQLite'.
'Azure Synapse Analytics Dedicated', 'Apache Spark', 'SQLite', and 'InterSystems IRIS'.
SystemRequirements: Java (>= 8)
License: Apache License 2.0
VignetteBuilder: knitr
Expand Down
3 changes: 2 additions & 1 deletion R/HelperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ renderSqlFile <- function(sourceFile, targetFile, warnOnMissingParameters = TRUE
#' @param sourceFile The source SQL file
#' @param targetFile The target SQL file
#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", "impala",
#' "sqlite", "netezza", "bigquery", "snowflake", "synapse", "spark", and "redshift" are supported.
#' "sqlite", "netezza", "bigquery", "snowflake", "synapse", "spark", "redshift"
#' and "iris" are supported.
#' @param oracleTempSchema DEPRECATED: use \code{tempEmulationSchema} instead.
#' @param tempEmulationSchema Some database platforms like Oracle and Impala do not truly support
#' temp tables. To emulate temp tables, provide a schema with write
Expand Down
9 changes: 6 additions & 3 deletions R/RenderSql.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ renderSql <- function(sql = "", warnOnMissingParameters = TRUE, ...) {
#'
#' @param sql The SQL to be translated
#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", "impala",
#' "sqlite", "sqlite extended", "netezza", "bigquery", "snowflake", "synapse", "spark", and "redshift" are supported.
#' "sqlite", "sqlite extended", "netezza", "bigquery", "snowflake", "synapse", "spark",
#' "redshift", and "iris" are supported.
#' Use \code{\link{listSupportedDialects}} to get the list of supported dialects.
#' @param oracleTempSchema DEPRECATED: use \code{tempEmulationSchema} instead.
#' @param tempEmulationSchema Some database platforms like Oracle and Impala do not truly support
Expand Down Expand Up @@ -201,7 +202,8 @@ translate <- function(sql,
#'
#' @param sql The SQL to be translated
#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", "impala",
#' "netezza", "bigquery", "snowflake", "synapse", "spark", and "redshift" are supported
#' "netezza", "bigquery", "snowflake", "synapse", "spark", "redshift", and
#' "iris" are supported
#' @param oracleTempSchema A schema that can be used to create temp tables in when using Oracle or
#' Impala.
#'
Expand Down Expand Up @@ -230,7 +232,8 @@ translateSql <- function(sql = "", targetDialect, oracleTempSchema = NULL) {
#'
#' @param sql The SQL to be translated
#' @param targetDialect The target dialect. Currently "oracle", "postgresql", "pdw", "impala",
#' "sqlite", "sqlite extended", "netezza", "bigquery", "snowflake", "synapse", "spark", and "redshift" are supported.
#' "sqlite", "sqlite extended", "netezza", "bigquery", "snowflake", "synapse", "spark",
#' "redshift", and "iris" are supported.
#' @param oracleTempSchema DEPRECATED: use \code{tempEmulationSchema} instead.
#' @param tempEmulationSchema Some database platforms like Oracle and Impala do not truly support
#' temp tables. To emulate temp tables, provide a schema with write
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Features
- Supports a simple markup syntax for making SQL parameterized, and renders parameterized SQL (containing the markup syntax) to executable SQL
- The syntax supports defining default parameter values
- The syntax supports if-then-else structures
- Has functions for translating SQL from one dialect (Microsoft SQL Server) to other dialects (Oracle, PostgreSQL, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, Microsoft PDW, Snowflake, Azure Synapse, Apache Spark and SQLite)
- Has functions for translating SQL from one dialect (Microsoft SQL Server) to other dialects (Oracle, PostgreSQL, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, Microsoft PDW, Snowflake, Azure Synapse, Apache Spark, SQLite, and InterSystems IRIS)
- Can be used as R package, Java library, or as stand-alone executable through a command-line interface

Examples
Expand Down
56 changes: 56 additions & 0 deletions inst/csv/replacementPatterns.csv
Original file line number Diff line number Diff line change
Expand Up @@ -1372,3 +1372,59 @@ sql server,...@([0-9]+|y)a,xxx@a
sql server,DROP TABLE IF EXISTS #@table;,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE #@table;"
sql server,DROP TABLE IF EXISTS @table;,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;"
sql server,CREATE TABLE IF NOT EXISTS @table (@definition);,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);"
iris,...@([0-9]+)a,xxx@a --???
iris,"IIF(@condition, @whentrue, @whenfalse)","CASE WHEN @condition THEN @whentrue ELSE @whenfalse END"
iris,TRY_CAST(@a),CAST(@a)
iris,+ '@a',|| '@a'
iris,'@a' +,'@a' ||
iris,CAST(@a AS varchar(@b)) +,CAST(@a AS varchar(@b)) ||
iris,+ CAST(@a AS varchar(@b)),|| CAST(@a AS varchar(@b))
iris,CAST(@a AS varchar) +,CAST(@a AS varchar) ||
iris,+ CAST(@a AS varchar),|| CAST(@a AS varchar)
iris,COUNT_BIG(@a),COUNT(@a)
iris,.dbo.,.
iris,CREATE TABLE #@table (@definition),CREATE GLOBAL TEMPORARY TABLE #@table (@definition)
iris,"WITH @a AS (@b), @c CREATE TABLE @d AS @e;","DROP TABLE IF EXISTS #@a;\n CREATE GLOBAL TEMPORARY TABLE #@a AS @b;\n WITH @c CREATE TABLE @d AS @e;\n DROP TABLE IF EXISTS #@a;"
iris,WITH @a AS (@b) CREATE TABLE @c AS SELECT @d;,DROP TABLE IF EXISTS #@a;\n CREATE GLOBAL TEMPORARY TABLE #@a AS @b;\n CREATE TABLE @c AS SELECT @d;\n DROP TABLE IF EXISTS #@a;
iris,"WITH @a AS (@b), @c CREATE GLOBAL TEMPORARY TABLE @d AS @e;","DROP TABLE IF EXISTS #@a;\n CREATE GLOBAL TEMPORARY TABLE #@a AS @b;\n WITH @c CREATE GLOBAL TEMPORARY TABLE @d AS @e;\n DROP TABLE IF EXISTS #@a;"
iris,WITH @a AS (@b) CREATE GLOBAL TEMPORARY TABLE @c AS @d;,DROP TABLE IF EXISTS #@a;\n CREATE GLOBAL TEMPORARY TABLE #@a AS @b;\n CREATE GLOBAL TEMPORARY TABLE @c AS @d;\n DROP TABLE IF EXISTS #@a;
iris,"IF OBJECT_ID('@table', 'U') IS NULL CREATE TABLE @table (@definition);",CREATE TABLE IF NOT EXISTS @table (@definition);
iris,"IF OBJECT_ID('@table', 'U') IS NOT NULL DROP TABLE @table;",DROP TABLE IF EXISTS @table;
iris,"IF OBJECT_ID('tempdb..#@table', 'U') IS NOT NULL DROP TABLE #@table;",DROP TABLE IF EXISTS #@table;
iris,PRIMARY KEY NONCLUSTERED,PRIMARY KEY
iris,"AS drvd(@a)","AS drvd(<start>@a)"
iris,"<start>@a, @b)","<start>@a, <start>@b)"
iris,"<start>","NULL AS "
iris,"FROM (VALUES @a) AS drvd(@b)","FROM (SELECT @b WHERE (0 = 1) UNION ALL VALUES @a) AS values_table"
iris,SELECT @a INTO #@b FROM @c;,CREATE GLOBAL TEMPORARY TABLE #@b AS SELECT @a FROM @c;
iris,SELECT @a INTO @b FROM @c;,CREATE TABLE @b AS SELECT @a FROM @c;
iris,SELECT @a INTO @b;,CREATE TABLE @b AS SELECT @a;
iris,SELECT @a INTO #@b;,CREATE GLOBAL TEMPORARY TABLE #@b AS SELECT @a;
iris,#,%temp_prefix%%session_id%
iris,UPDATE STATISTICS @a;,TUNE TABLE @a;
iris,"--HINT BUCKET(@a, @b)", -- haven't looked into this yet, skip it for now
iris,"--HINT PARTITION(@a @b)", -- haven't looked into this yet, skip it for now
iris,"--HINT DISTRIBUTE_ON_KEY(@key)", -- haven't looked into this yet, skip it for now
iris,"DATEFROMPARTS(@year,@month,@day)","TO_DATE(TO_CHAR(@year,'FM0000')||'-'||TO_CHAR(@month,'FM00')||'-'||TO_CHAR(@day,'FM00'), 'YYYY-MM-DD')"
iris,"DATETIMEFROMPARTS(@year,@month,@day,@hour,@minute,@second,@ms)","TO_TIMESTAMP(TO_CHAR(@year,'FM0000')||'-'||TO_CHAR(@month,'FM00')||'-'||TO_CHAR(@day,'FM00')||' '||TO_CHAR(@hour,'FM00')||':'||TO_CHAR(@minute,'FM00')||':'||TO_CHAR(@second,'FM00')||'.'||TO_CHAR(@ms,'FM000'), 'YYYY-MM-DD HH24:MI:SS.FF')"
iris," DATEADD(d, @a, @b) AS"," TO_DATE(DATEADD(d, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(dd, @a, @b) AS"," TO_DATE(DATEADD(dd, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(day, @a, @b) AS"," TO_DATE(DATEADD(day, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(m, @a, @b) AS"," TO_DATE(DATEADD(m, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(mm, @a, @b) AS"," TO_DATE(DATEADD(mm, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(yy, @a, @b) AS"," TO_DATE(DATEADD(yy, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," DATEADD(yyyy, @a, @b) AS"," TO_DATE(DATEADD(yyyy, @a, @b),'YYYY-MM-DD HH:MI:SS') AS"
iris," COALESCE(p.birth_datetime", COALESCE(CAST(p.birth_datetime AS DATE)
iris,"CONCAT(p.year_of_birth, @b, @c)",p.year_of_birth||'-'||@b||'-'|| @c
iris,"CONCAT(@a, @b,","@a || CONCAT(@b,"
iris,"CONCAT(@a,@b)",@a || @b
iris,CREATE CLUSTERED INDEX @index_name ON @table (@variable);,CREATE INDEX @index_name ON @table (@variable);
iris,CREATE INDEX @index_name ON @table (@variable) WHERE @b;,CREATE INDEX @index_name ON @table (@variable);
iris,AS MIN,AS "MIN"
iris,AS MAX,AS "MAX"
iris,AS COUNT,AS "COUNT"
iris,STDEV(@a),STDDEV(@a)
iris,STDEV_POP(@a),STDDEV_POP(@a)
iris,STDEV_SAMP(@a),STDDEV_SAMP(@a)
iris,EOMONTH(@date),LAST_DAY(@date)
iris,.DOMAIN ,."DOMAIN"
1 change: 1 addition & 0 deletions inst/csv/supportedDialects.csv
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ sqlite extended,SQLite Extended Syntax
duckdb,DuckDB
snowflake,Snowflake
synapse,Azure Synapse Analytics Dedicated
iris,InterSystems IRIS
90 changes: 45 additions & 45 deletions inst/shinyApps/SqlDeveloper/ui.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
library(shiny)
library(shinydashboard)
source("widgets.R")

dashboardPage(
dashboardHeader(title = "SqlRender Developer"),
dashboardSidebar(
sidebarMenu(
menuItemFileInput("open", "Open file", icon = shiny::icon("folder-open")),
menuItemDownloadLink("save", "Save", icon = shiny::icon("save")),
menuItem("Open new tab", href = "", icon = shiny::icon("plus-square")),
menuItemCopyTextAreaToClipboard("source", "Copy source to clipboard"),
menuItemCopyDivToClipboard("target", "Copy target to clipboard")
)
),
dashboardBody(
fluidRow(
column(width = 9,
box(
title = "Source: OHDSI SQL", width = NULL, status = "primary",
textAreaInput("source", NULL, width = "100%", height = "300px")
),
box(
title = "Target: Rendered translation", width = NULL,
# tags$table(width = "100%",
# tags$tr(
# tags$td(align = "left", actionButton("renderTranslate", "Render and translate")),
# tags$td(align = "right", checkboxInput("continuous", "Auto render and translate")))),
pre(textOutput("target"))
)
),
column(width = 3,
box(background = "light-blue",
h4("Target dialect"), width = NULL,
selectInput("dialect", NULL, choices = c("BigQuery", "Impala", "Netezza", "Oracle", "PDW", "PostgreSQL", "RedShift", "SQL Server", "SQLite", "Hive", "Spark", "Snowflake", "Synapse"), selected = "SQL Server"),
h4("Temp emulation schema"),
textInput("tempEmulationSchema", NULL),
h4("Parameters"),
uiOutput("parameterInputs"),
textOutput("warnings")
)
)
)
)
)
library(shiny)
library(shinydashboard)
source("widgets.R")

dashboardPage(
dashboardHeader(title = "SqlRender Developer"),
dashboardSidebar(
sidebarMenu(
menuItemFileInput("open", "Open file", icon = shiny::icon("folder-open")),
menuItemDownloadLink("save", "Save", icon = shiny::icon("save")),
menuItem("Open new tab", href = "", icon = shiny::icon("plus-square")),
menuItemCopyTextAreaToClipboard("source", "Copy source to clipboard"),
menuItemCopyDivToClipboard("target", "Copy target to clipboard")
)
),
dashboardBody(
fluidRow(
column(width = 9,
box(
title = "Source: OHDSI SQL", width = NULL, status = "primary",
textAreaInput("source", NULL, width = "100%", height = "300px")
),
box(
title = "Target: Rendered translation", width = NULL,
# tags$table(width = "100%",
# tags$tr(
# tags$td(align = "left", actionButton("renderTranslate", "Render and translate")),
# tags$td(align = "right", checkboxInput("continuous", "Auto render and translate")))),
pre(textOutput("target"))
)
),
column(width = 3,
box(background = "light-blue",
h4("Target dialect"), width = NULL,
selectInput("dialect", NULL, choices = c("BigQuery", "Impala", "Netezza", "Oracle", "PDW", "PostgreSQL", "RedShift", "SQL Server", "SQLite", "Hive", "Spark", "Snowflake", "Synapse", "InterSystems IRIS" = "iris"), selected = "SQL Server"),
h4("Temp emulation schema"),
textInput("tempEmulationSchema", NULL),
h4("Parameters"),
uiOutput("parameterInputs"),
textOutput("warnings")
)
)
)
)
)
3 changes: 2 additions & 1 deletion man/translate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/translateSingleStatement.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/translateSql.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/translateSqlFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit e5463e2

Please sign in to comment.