renderSql: renderSql

Description Usage Arguments Details Value Examples

Description

renderSql Renders SQL code based on parameterized SQL and parameter values.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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")
renderSql("SELECT * FROM @a {@a == 'myTable' & @b != 'x'}?{WHERE @b = 1};",
          a = "myTable",
          b = "y")

hxia/SqlRender4Impala documentation built on May 17, 2019, 9:15 p.m.