R Studio dbWriteTable error writing to Hive SQL
I’m using R Studio to ingest a csv file and write it to a table in Hive SQL using the following code:
library(DBI)
library(readr)
db_connection <- get_connection()
table_name <- "dbname.tablename"
csv_file <- "filelocation/datafile.csv"
table_data <- read_csv(csv_file)
dbGetQuery(db_connection, paste0("DROP TABLE ",table_name))
dbWriteTable(db_connection,table_name,table_data)
However I’m receiving the error:
Syntax or semantic analysis error thrown in server while executing query. Error message from server: Error while compiling statement: FAILED: ParseException line 2:8 cannot recognize input near '?' ',' '?' in expression specification
<SQL> 'INSERT INTO `dbname.tablename` (`col1`, `col2`, `col3`)
VALUES (?, ?, ?)'
(I’ve made things such as db and table name generic names)
It seems dbWriteTable isn’t reading the csv file/data frame properly. It’s a 3 column csv file and all data are character formats.
Any help would be appreciated!
Code is above and what I expect is that the csv is read into a data frame which is then used to create the table. It’s not complicated data but I must be doing something wrong?
Read more here: Source link
