Learn R Programming

RAthena (version 1.3.0)

db_copy_to: S3 implementation of db_copy_to for Athena

Description

This is an Athena method for dbplyr function db_copy_to to create an Athena table from a data.frame.

Usage

db_copy_to.AthenaConnection(con, table, values, overwrite = FALSE,
  append = FALSE, types = NULL, partition = NULL,
  s3_location = NULL, file_type = c("csv", "tsv", "parquet"), ...)

Arguments

con

A dbConnect object, as returned by dbConnect()

table

A character string specifying a table name. Names will be automatically quoted so you can use any sequence of characters, not just any valid bare table name.

values

A data.frame to write to the database.

overwrite

Allow overwriting the destination table. Cannot be `TRUE` if `append` is also `TRUE`.

append

Allow appending to the destination table. Cannot be `TRUE` if `overwrite` is also `TRUE`.

types

Additional field types used to override derived types.

partition

Partition Athena table (needs to be a named list or vector) for example: c(var1 = "2019-20-13")

s3_location

s3 bucket to store Athena table, must be set as a s3 uri for example ("s3://mybucket/data/")

file_type

What file type to store data.frame on s3, RAthena currently supports ["csv", "tsv", "parquet"]. Note: "parquet" format is supported by the arrow package and it will need to be installed to utilise the "parquet" format.

...

other parameters currently not supported in RAthena

Value

db_copy_to returns table name

See Also

AthenaWriteTables

Examples

Run this code
# NOT RUN {
# Note: 
# - Require AWS Account to run below example.
# - Different connection methods can be used please see `RAthena::dbConnect` documnentation

library(DBI)
library(dplyr)

# Demo connection to Athena using profile name 
con <- dbConnect(RAthena::athena())

# List existing tables in Athena
dbListTables(con)

# Write data.frame to Athena table
copy_to(con, mtcars,
        s3_location = "s3://mybucket/data/")
             
# Checking if uploaded table exists in Athena
dbExistsTable(con, "mtcars")

# Write Athena table from tbl_sql
athena_mtcars <- tbl(con, "mtcars")
mtcars_filter <- athena_mtcars %>% filter(gear >=4)

copy_to(con, mtcars_filter)

# Checking if uploaded table exists in Athena
dbExistsTable(con, "mtcars_filter") 

# Disconnect from Athena
dbDisconnect(con)
# }

Run the code above in your browser using DataLab