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

Teradata® Package for R Function Reference

Product
Teradata Package for R
Release Number
17.00
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B700-4007-090K
Language
English (United States)

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