MyNixOS website logo
Description

Rendering Parameterized SQL and Translation to Dialects.

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'.

SqlRender

Build Status codecov.io CRAN_Status_Badge CRAN_Status_Badge

SqlRender is part of HADES.

Introduction

This is an R package for rendering parameterized SQL, and translating it to different SQL dialects. SqlRender can also be used as a stand-alone Java library and a command-line executable.

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)
  • Can be used as R package, Java library, or as stand-alone executable through a command-line interface

Examples

This example shows the use of parameters, as well as SqlRender's {if} ? {then} : {else} syntax:

sql <- render("SELECT * FROM @a; {@b != ''}?{USE @b;}", a = "my_table", b = "my_schema")

will produce the variable sql containing this value:

"SELECT * FROM my_table; USE my_schema;"

subsequently running this code

sql <- translate(sql, "oracle")

will produce the variable sql containing this value:

"SELECT * FROM my_table; ALTER SESSION SET current_schema =  my_schema;"

SqlDeveloper

The SqlDeveloper Shiny app is included in the SqlRender R package, and allows viewing the rendering and translation on the fly as you develop your SQL. The SqlDeveloper app is also available online here.

Technology

The SqlRender package is an R package wrapped around a Java library. The rJava package is used as interface.

The Java library is available as a JAR file.

System Requirements

Running the package requires R with the package rJava installed. Also requires Java 1.6 or higher. It is highly recommended for best performance to use a version of R that is at least version 4 or higher otherwise, unexpected bugs or errors may occur.

Installation

R package

In R, to install the latest stable version, install from CRAN:

install.packages("SqlRender")

To install the latest development version, install from GitHub:

install.packages("remotes")
remotes::install_github("ohdsi/SqlRender", ref = "develop")

Once installed, you can try out SqlRender in a Shiny app that comes with the package:

library(SqlRender)
launchSqlRenderDeveloper()

Java library

You can fetch the JAR file in the inst/java folder of this repository, or use Maven:

  1. First add the SqlRender repository so that maven can find and download the SqlRender artifact automatically:
<repository>
  <id>ohdsi</id>
  <name>repo.ohdsi.org</name>
  <url>https://repo.ohdsi.org/nexus/content/repositories/releases</url>
</repository>
<repository>
  <id>ohdsi.snapshots</id>
  <name>repo.ohdsi.org-snapshots</name>
  <url>https://repo.ohdsi.org/nexus/content/repositories/snapshots</url>
  <releases>
      <enabled>false</enabled>
  </releases>
  <snapshots>
      <enabled>true</enabled>
  </snapshots>
</repository>

2: Include the SqlRender dependency in your pom.xml

<dependency>
	<groupId>org.ohdsi.sql</groupId>
	<artifactId>SqlRender</artifactId>
	<version>1.9.2-SNAPSHOT</version>
</dependency>

Command-line executable

You can fetch the JAR file in the inst/java folder of this repository, or use Maven as described above. Run this from the command line to get a list of options:

java -jar SqlRender.jar ?

User Documentation

Documentation can be found on the package website.

PDF versions of the documentation are also available:

Support

Contributing

Read here how you can contribute to this package.

License

SqlRender is licensed under Apache License 2.0

Development

SqlRender is being developed in R Studio.

Development status

Stable. The code is actively being used in several projects.

Acknowledgements

  • This project is supported in part through the National Science Foundation grant IIS 1251151.
Metadata

Version

1.18.0

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows