SQL Translation Extensions
Description
An important feature that 'dbplyr' provides is the ability
to take expressions in R and map them to corresponding
expressions in SQL. tdplyr maps certain window, aggregate,
and scalar functions to SQL expressions when summarize
, mutate
,
or filter
is used.
Details
See vignette('sql-translation', package = 'tdplyr')
for a list of all the mappings.
Note that functions not explicitly mapped above will be translated to sql literally.
Examples
translate_sql(mean(x, na.rm = TRUE), window = FALSE, con = dbplyr::simulate_teradata())
translate_sql(sdp(distinct(x), na.rm = TRUE), window = FALSE, con = dbplyr::simulate_teradata())
translate_sql(mean(x, na.rm = TRUE), con = dbplyr::simulate_teradata())
translate_sql(sdp(x, na.rm = TRUE), con = dbplyr::simulate_teradata())
# The DISTINCT clause is not permitted in window aggregate functions
tryCatch({
translate_sql(sum(distinct(x), na.rm = TRUE), con = dbplyr::simulate_teradata())
},error=function(e) {
geterrmessage()
})
# The DISTINCT clause is allowed in aggregate functions
translate_sql(sdp(distinct(x), na.rm = TRUE), window = FALSE, con = dbplyr::simulate_teradata())