For the complete documentation index, see llms.txt. This page is also available as Markdown.

redivis$connect_dbi

redivis$connect_dbi() → DBI::DBIConnection

Returns a DBI connection that can be used by dbplyr and other interfaces that work with DBI. This connection will be globally scoped, and all table names must be appropriately qualified.

To create a connection scoped to particulary dataset or workflow, see:

For advanced use cases, you can also access the Redivis DBI interface at redivis::RedivisDBI. redivis$connect_dbi() is the same as calling: DBI::dbConnect(redivis::RedivisDBI())

Returns:

Examples

con <- redivis$connect_dbi()

tbl(con, "demo.ghcn_daily_weather_data.stations") |> filter(latitude > 0) |> collect()

# Prints a tibble with the relevant weather stations

Supported dplyr functions

DBI connections can be used with all of the standard dplyr verbs (filter(), mutate(), summarise(), joins, etc.). Within these verbs, the following R functions are translated to Redivis SQL:

Category
Functions

Math and operators

+, -, *, /, ^, %%, %/%, %||%, abs(), sqrt(), exp(), log(), log2(), log10(), round(), floor(), ceiling(), pmin(), pmax()

Type conversion

as.integer(), as.numeric(), as.double(), as.character(), as.logical(), as.Date(), as.POSIXct(), lubridate::as_date(), lubridate::as_datetime()

Conditionals

ifelse(), if_else(), case_when(), coalesce(), is.na(), between(), %in%

Strings

nchar(), tolower(), toupper(), trimws(), paste(), paste0(), substr(), substring(), startsWith(), endsWith(), grepl(), sub(), gsub(), and from stringr: str_detect(), str_starts(), str_ends(), str_extract(), str_replace(), str_replace_all(), str_remove(), str_remove_all(), str_trim(), str_squish(), str_pad(), str_to_lower(), str_to_upper(), str_to_title(), str_c(), str_length(), str_sub()

Dates and times

Sys.Date(), Sys.time(), difftime(), and from lubridate: today(), now(), year(), isoyear(), quarter(), month(), week(), isoweek(), day(), mday(), yday(), wday(), hour(), minute(), second(), floor_date(), and from clock: get_year(), get_month(), get_day(), get_hour(), get_minute(), get_second(), add_days(), add_weeks(), add_months(), add_quarters(), add_years(), date_build(), date_count_between()

Aggregates

n(), n_distinct(), sum(), mean(), min(), max(), sd(), var(), cor(), cov(), median(), quantile(), any(), all(), and from stringr: str_flatten()

Window functions

row_number(), min_rank(), rank(), dense_rank(), lead(), lag(), first(), last(), cumsum(), and the aggregate functions above (other than median(), quantile(), n_distinct(), str_flatten(), any(), all(), cor(), and cov())

The following differences from R's behavior apply:

  • %/% and %% round toward negative infinity, as in R, and always return a double.

  • median() and quantile() are approximate. quantile() takes a single probs value.

  • str_replace(), str_remove(), and sub() replace only the first match, and require a literal pattern and a replacement without backreferences. To use a column as the pattern, or to use backreferences, use str_replace_all() or gsub() to replace every match.

  • difftime() only supports units = "days", and date_count_between() only supports a precision of "day" or "week".

  • month() and wday() don't support label = TRUE, and wday() only supports week_start = 7. floor_date() doesn't support multiples of a unit (e.g., "2 days").

  • second() returns whole seconds.

  • Redivis dateTime variables don't have a time zone, so as.POSIXct() and Sys.time() produce a DATETIME, and R POSIXct values used within a query are converted to UTC.

An error will be raised if a function is called with arguments that can't be translated.

Last updated

Was this helpful?