Package ‘SqlRender’ June 9, 2017 Type Package Title Rendering Parameterized SQL and Translation to Dialects Version 1.4.3 Date 2017-06-09 Maintainer Martijn Schuemie Description A rendering tool for parameterized SQL that also translates into different SQL dialects. These dialects include Sql Server, Oracle, PostgreSql, Amazon RedShift, Impala, IBM Netezza, Google BigQuery, and Microsoft PDW. License Apache License 2.0 VignetteBuilder knitr URL https://github.com/OHDSI/SqlRender BugReports https://github.com/OHDSI/SqlRender/issues Imports rJava Suggests testthat, knitr, rmarkdown, shiny, shinydashboard, formatR LazyData false RoxygenNote 6.0.1

R topics documented: camelCaseToSnakeCase . createRWrapperForSql . . launchSqlRenderDeveloper loadRenderTranslateSql . . readSql . . . . . . . . . . renderSql . . . . . . . . . renderSqlFile . . . . . . . snakeCaseToCamelCase . splitSql . . . . . . . . . . SqlRender . . . . . . . . . translateSql . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . . 1

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

2 2 3 3 4 5 6 7 7 8 8

2

createRWrapperForSql translateSqlFile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . writeSql . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Index

9 9 11

camelCaseToSnakeCase

Convert a camel case string to snake case

Description Convert a camel case string to snake case Usage camelCaseToSnakeCase(string) Arguments string

The string to be converted

Value A string Examples camelCaseToSnakeCase("cdmDatabaseSchema") # > 'cdm_database_schema'

createRWrapperForSql

Create an R wrapper for SQL

Description createRWrapperForSql creates an R wrapper for a parameterized SQL file. The created R script file will contain a single function, that executes the SQL, and accepts the same parameters as specified in the SQL. Usage createRWrapperForSql(sqlFilename, rFilename, packageName, createRoxygenTemplate = TRUE) Arguments sqlFilename

The SQL file.

rFilename

The name of the R file to be generated. Defaults to the name of the SQL file with the extention reset to R.

packageName The name of the package that will contains the SQL file. createRoxygenTemplate If true, a template of Roxygen comments will be added.

launchSqlRenderDeveloper

3

Details This function reads the declarations of defaults in the parameterized SQL file, and creates an R function that exposes the parameters. It uses the loadRenderTranslateSql function, and assumes the SQL will be used inside a package. To use inside a package, the SQL file should be placed in the inst/sql/sql_server folder of the package. Examples ## Not run: # This will create a file called CohortMethod.R: createRWrapperForSql("CohortMethod.sql", packageName = "CohortMethod") ## End(Not run)

launchSqlRenderDeveloper Launch the SqlRender Developer Shiny app

Description Launch the SqlRender Developer Shiny app Usage launchSqlRenderDeveloper(launch.browser = TRUE) Arguments launch.browser Should the app be launched in your default browser, or in a Shiny window. Note: copying to clipboard will not work in a Shiny window. Details Launches a Shiny app that allows the user to develop SQL and see how it translates to the supported dialects.

loadRenderTranslateSql Load, render, and translate a SQL file in a package

Description loadRenderTranslateSql Loads a SQL file contained in a package, renders it and translates it to the specified dialect Usage loadRenderTranslateSql(sqlFilename, packageName, dbms = "sql server", ..., oracleTempSchema = NULL)

4

readSql

Arguments sqlFilename

The source SQL file

packageName

The name of the package that contains the SQL file

dbms

The target dialect. Currently ’sql server’, ’oracle’, ’postgres’, and ’redshift’ are supported

... Parameter values used for renderSql oracleTempSchema A schema that can be used to create temp tables in when using Oracle. Details This function looks for a SQL file with the specified name in the inst/sql/ folder of the specified package. If it doesn’t find it in that folder, it will try and load the file from the inst/sql/sql_server folder and use the translateSql function to translate it to the requested dialect. It will subsequently call the renderSql function with any of the additional specified parameters. Value Returns a string containing the rendered SQL. Examples ## Not run: renderedSql <- loadRenderTranslateSql("CohortMethod.sql", packageName = "CohortMethod", dbms = connectionDetails$dbms, CDM_schema = "cdmSchema") ## End(Not run)

readSql

Reads a SQL file

Description readSql loads SQL from a file Usage readSql(sourceFile) Arguments sourceFile

The source SQL file

Details readSql loads SQL from a file Value Returns a string containing the SQL.

renderSql

5

Examples ## Not run: readSql("myParamStatement.sql") ## End(Not run)

renderSql

renderSql

Description renderSql Renders SQL code based on parameterized SQL and parameter values. Usage renderSql(sql = "", ...) Arguments sql

The parameterized SQL

...

Parameter values

Details This function takes parameterized SQL and a list of parameter values and renders the SQL that can be send to the server. Parameterization syntax: @parameterName Parameters are indicated using a @ prefix, and are replaced with the actual values provided in the renderSql call. {DEFAULT @parameterName = parameterValue} Default values for parameters can be defined using curly and the DEFAULT keyword. {if}?{then}:{else} The if-then-else pattern is used to turn on or off blocks of SQL code. Value A list containing the following elements: parameterizedSql The original parameterized SQL code sql The rendered sql Examples renderSql("SELECT * FROM @a;", a = "myTable") renderSql("SELECT * FROM @a {@b}?{WHERE x = 1};", a = "myTable", b = "true") renderSql("SELECT * FROM @a {@b == ''}?{WHERE x = 1}:{ORDER BY x};", a = "myTable", b = "true") renderSql("SELECT * FROM @a {@b != ''}?{WHERE @b = 1};", a = "myTable", b = "y") renderSql("SELECT * FROM @a {1 IN (@c)}?{WHERE @b = 1};", a = "myTable", b = "y", c = c(1, 2, 3, 4)) renderSql("{DEFAULT @b = \"someField\"}SELECT * FROM @a {@b != ''}?{WHERE @b = 1};", a = "myTable")

6

renderSqlFile renderSql("SELECT * FROM @a {@a == 'myTable' & @b != 'x'}?{WHERE @b = 1};", a = "myTable", b = "y")

renderSqlFile

Render a SQL file

Description renderSqlFile Renders SQL code in a file based on parameterized SQL and parameter values, and writes it to another file.

Usage renderSqlFile(sourceFile, targetFile, ...) Arguments sourceFile

The source SQL file

targetFile

The target SQL file

...

Parameter values

Details This function takes parameterized SQL and a list of parameter values and renders the SQL that can be send to the server. Parameterization syntax: @parameterName Parameters are indicated using a @ prefix, and are replaced with the actual values provided in the renderSql call. {DEFAULT @parameterName = parameterValue} Default values for parameters can be defined using curly and the DEFAULT keyword. {if}?{then}:{else} The if-then-else pattern is used to turn on or off blocks of SQL code.

Examples ## Not run: renderSqlFile("myParamStatement.sql", "myRenderedStatement.sql", a = "myTable") ## End(Not run)

snakeCaseToCamelCase

snakeCaseToCamelCase

7

Convert a snake case string to camel case

Description Convert a snake case string to camel case Usage snakeCaseToCamelCase(string) Arguments string

The string to be converted

Value A string Examples snakeCaseToCamelCase("cdm_database_schema") # > 'cdmDatabaseSchema'

splitSql

splitSql

Description splitSql splits a string containing multiple SQL statements into a vector of SQL statements Usage splitSql(sql) Arguments sql

The SQL string to split into separate statements

Details This function is needed because some DBMSs (like ORACLE) do not accepts multiple SQL statements being sent as one execution. Value A vector of strings, one for each SQL statement Examples splitSql("SELECT * INTO a FROM b; USE x; DROP TABLE c;")

8

translateSql

SqlRender

SqlRender

Description SqlRender

translateSql

translateSql

Description translateSql translates SQL from one dialect to another Usage translateSql(sql = "", targetDialect, oracleTempSchema = NULL, sourceDialect) Arguments sql

The SQL to be translated

targetDialect

The target dialect. Currently "oracle", "postgresql", "pdw", "impala", "netezza", "bigquery", and "redshift" are supported oracleTempSchema A schema that can be used to create temp tables in when using Oracle or Impala. sourceDialect

Deprecated: The source dialect. Currently, only "sql server" for Microsoft SQL Server is supported

Details This function takes SQL in one dialect and translates it into another. It uses simple pattern replacement, so its functionality is limited. Value A list containing the following elements: originalSql The original parameterized SQL code sql The translated SQL Examples translateSql("USE my_schema;", targetDialect = "oracle")

translateSqlFile

translateSqlFile

9

Translate a SQL file

Description This function takes SQL and translates it to a different dialect. Usage translateSqlFile(sourceFile, targetFile, sourceDialect, targetDialect, oracleTempSchema = NULL) Arguments sourceFile

The source SQL file

targetFile

The target SQL file

sourceDialect

Deprecated: The source dialect. Currently, only ’sql server’ for Microsoft SQL Server is supported

targetDialect The target dialect. Currently ’oracle’, ’postgresql’, and ’redshift’ are supported oracleTempSchema A schema that can be used to create temp tables in when using Oracle. Details This function takes SQL and translates it to a different dialect. Examples ## Not run: translateSqlFile("myRenderedStatement.sql", "myTranslatedStatement.sql", targetDialect = "postgresql") ## End(Not run)

writeSql

Write SQL to a SQL (text) file

Description writeSql writes SQL to a file Usage writeSql(sql, targetFile) Arguments sql

A string containing the sql

targetFile

The target SQL file

10

writeSql

Details writeSql writes SQL to a file Examples ## Not run: sql <- "SELECT * FROM @table_name" writeSql(sql, "myParamStatement.sql") ## End(Not run)

Index camelCaseToSnakeCase, 2 createRWrapperForSql, 2 launchSqlRenderDeveloper, 3 loadRenderTranslateSql, 3 readSql, 4 renderSql, 5 renderSqlFile, 6 snakeCaseToCamelCase, 7 splitSql, 7 SqlRender, 8 SqlRender-package (SqlRender), 8 translateSql, 8 translateSqlFile, 9 writeSql, 9

11

SqlRender - GitHub

Description A rendering tool for parameterized SQL that also translates into different SQL ... Load, render, and translate a SQL file in a package. Description.

114KB Sizes 1 Downloads 166 Views

Recommend Documents

Using SqlRender - GitHub
6. 3.5 Case sensitivity in string comparisons . .... would have had no clue the two fields were strings, and would incorrectly leave the plus sign. Another clue that.

GitHub
domain = meq.domain(10,20,0,10); cells = meq.cells(domain,num_freq=200, num_time=100); ...... This is now contaminator-free. – Observe the ghosts. Optional ...

GitHub
data can only be “corrected” for a single point on the sky. ... sufficient to predict it at the phase center (shifting ... errors (well this is actually good news, isn't it?)

Torsten - GitHub
Metrum Research Group has developed a prototype Pharmacokinetic/Pharmacodynamic (PKPD) model library for use in Stan 2.12. ... Torsten uses a development version of Stan, that follows the 2.12 release, in order to implement the matrix exponential fun

Untitled - GitHub
The next section reviews some approaches adopted for this problem, in astronomy and in computer vision gener- ... cussed below), we would question the sensitivity of a. Delaunay triangulation alone for capturing the .... computation to be improved fr

ECf000172411 - GitHub
Robert. Spec Sr Trading Supt. ENA West Power Fundamental Analysis. Timothy A Heizenrader. 1400 Smith St, Houston, Tx. Yes. Yes. Arnold. John. VP Trading.

Untitled - GitHub
Iwip a man in the middle implementation. TOR. Andrea Marcelli prof. Fulvio Risso. 1859. Page 3. from packets. PEX. CethernetDipo topo data. Private. Execution. Environment to the awareness of a connection. FROG develpment. Cethernet DipD tcpD data. P

BOOM - GitHub
Dec 4, 2016 - 3.2.3 Managing the Global History Register . ..... Put another way, instructions don't need to spend N cycles moving their way through the fetch ...

Supervisor - GitHub
When given an integer, the supervisor terminates the child process using. Process.exit(child, :shutdown) and waits for an exist signal within the time.

robtarr - GitHub
http://globalmoxie.com/blog/making-of-people-mobile.shtml. Saturday, October ... http://24ways.org/2011/conditional-loading-for-responsive-designs. Saturday ...

MY9221 - GitHub
The MY9221, 12-channels (R/G/B x 4) c o n s t a n t current APDM (Adaptive Pulse Density. Modulation) LED driver, operates over a 3V ~ 5.5V input voltage ...

fpYlll - GitHub
Jul 6, 2017 - fpylll is a Python (2 and 3) library for performing lattice reduction on ... expressiveness and ease-of-use beat raw performance.1. 1Okay, to ... py.test for testing Python. .... GSO complete API for plain Gram-Schmidt objects, all.

article - GitHub
2 Universidad Nacional de Tres de Febrero, Caseros, Argentina. ..... www-nlpir.nist.gov/projects/duc/guidelines/2002.html. 6. .... http://singhal.info/ieee2001.pdf.

PyBioMed - GitHub
calculate ten types of molecular descriptors to represent small molecules, including constitutional descriptors ... charge descriptors, molecular properties, kappa shape indices, MOE-type descriptors, and molecular ... The molecular weight (MW) is th

MOC3063 - GitHub
IF lies between max IFT (15mA for MOC3061M, 10mA for MOC3062M ..... Dual Cool™ ... Fairchild's Anti-Counterfeiting Policy is also stated on ourexternal website, ... Datasheet contains the design specifications for product development.

MLX90615 - GitHub
Nov 8, 2013 - of 0.02°C or via a 10-bit PWM (Pulse Width Modulated) signal from the device. ...... The chip supports a 2 wires serial protocol, build with pins SDA and SCL. ...... measure the temperature profile of the top of the can and keep the pe

Covarep - GitHub
Apr 23, 2014 - Gilles Degottex1, John Kane2, Thomas Drugman3, Tuomo Raitio4, Stefan .... Compile the Covarep.pdf document if Covarep.tex changed.

SeparableFilter11 - GitHub
1. SeparableFilter11. AMD Developer Relations. Overview ... Load the center sample(s) int2 i2KernelCenter ... Macro defines what happens at the kernel center.

Programming - GitHub
Jan 16, 2018 - The second you can only catch by thorough testing (see the HW). 5. Don't use magic numbers. 6. Use meaningful names. Don't do this: data("ChickWeight") out = lm(weight~Time+Chick+Diet, data=ChickWeight). 7. Comment things that aren't c

SoCsploitation - GitHub
Page 2 ... ( everything – {laptops, servers, etc.} ) • Cheap and low power! WTF is a SoC ... %20Advice_for_Shellcode_on_Embedded_Syst ems.pdf. Tell me more! ... didn't destroy one to have pretty pictures… Teridian ..... [email protected].

Datasheet - GitHub
Dec 18, 2014 - Compliant with Android K and L ..... 9.49 SENSORHUB10_REG (37h) . .... DocID026899 Rev 7. 10. Embedded functions register mapping .