read_sql: Uses boto3 (in python) to send an sql query to athena and...

View source: R/read.R

read_sqlR Documentation

Uses boto3 (in python) to send an sql query to athena and return an R dataframe, tibble or data.table based on user preference.

Description

Uses boto3 (in python) to send an sql query to athena and return an R dataframe, tibble or data.table based on user preference.

Usage

read_sql(sql_query, return_df_as = "tibble")

Arguments

sql_query

A string specifying the SQL query you want to send to athena. See packages github readme for info on the flavour of SQL Athena uses.

return_df_as

String specifying what the table should be returned as i.e. 'dataframe', 'tibble' (converts data using tibble::as_tibble) or 'data.table' (converts data using data.table::as.data.table). Default is 'tibble'. Not all tables returned are a DataFrame class.

Details

Will send an SQL query to Athena and wait for it to complete. Once the query has completed the resulting sql query will be read using arrow. Function returns dataframe. If needing more a more bespoke or self defined data reading function and arguments use dbtools::start_query_and_wait to send an SQL query and return the s3 path to data in csv format.

Value

A table as a dataframe, tibble or data.table

Examples

# Read an sql query returning a tibble
```
df <- dbtools::read_sql(
  "SELECT * from crest_v1.flatfile limit 10000",
  return_df_as="tibble"
)
```

moj-analytical-services/dbtools documentation built on Sept. 29, 2024, 2:06 a.m.