Teradata R Package Function Reference | 17.00 - 17.00 - translate_sql - Teradata R Package

Teradata® R Package Function Reference

prodname
Teradata R Package
vrm_release
17.00
created_date
September 2020
category
Programming Reference
featnum
B700-4007-090K

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())